数据库帮助尝试通过用户从组中获取功能
我需要检查用户是否是一个组的一部分,该组具有使他们能够访问用户管理页面的功能。我当前所拥有的是
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
我不确定如何检查他们是否在用户控制器的表中具有字符串用户管理可以有人帮忙吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在这里谈论的是访问控制,请停止你正在做的事情并查看众多优秀的授权/ACL 精华之一。例如,使用 acl9 你可以得到一些更容易理解和更具表现力的代码,例如:
Rolling this stuff你自己是一个糟糕的举动,你最终会在你的应用程序中交织出大量混乱的代码,非常难以维护,并且不可能确保它始终执行你需要的操作。
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:
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.