Reputation: 5005
I need to check whether a USER is a part of a group which has functions which give them access to a usermanagement page.. what i current have is
def user_managment
# If they are in group 1 AND user has function id 1 (user management)
if current_user.group_ids.include?(1) && current_user.function_ids.include?(1)#&& group.function_ids.include?(1)
flash[:error] = "You have access to user management!"
else
flash[:error] = "You have DO NOT access to user management!"
end
if current_user.group_ids.include?(1) && group_ids(1).function_ids.include?(1)
flash[:error] = "Test"
end
end
im unsure how do check if they have the string user management in the table from the userscontrollers can anyone help?
Upvotes: 1
Views: 39
Reputation: 27971
What you're talking about here is access control, please please please PLEASE, stop what you're doing and look at one of the many, excellent authorization/ACL gems out there. For example, using acl9 you could have some code that's much more comprehensible and expressive, such as:
access_control do
allow :manager, :of => User, :to => :user_management
end
Rolling this stuff yourself is a bad move, and you'll end up with a lot of messy code intertwined through your app, very hard to maintain, and impossible to ensure it's always doing what you need it to.
Upvotes: 3