Rails 3:如何包含基于角色的操作?
我的 RPG 网站上有不同的角色。每个用户可以拥有多个角色,并基于此可以访问功能。假设用户是一名教师和主任,他应该访问一个页面来管理他的科目,另一个页面来管理所有网站。
有些人拥有超过 5 个角色,而在标题中每个办公室有 5 个链接就变得非常尴尬。我怎样才能根据角色采取行动包括其他人?
事实上,我想在一个独特的页面上显示用户可用的所有办公室,包括由单个操作管理的办公室。这怎么可能?
先感谢您 !
PS:动作在不同的控制器中
I've got different roles on my RPG website. Each user can have many roles and based on this can access features. Let's say for instance a user is a teacher and director, he should access a page to manage his subjects and another to manage all the website.
Some people have more than 5 roles and it becomes really awkward to have 5 links to each office in the header. How can I have an action to include others based on roles ?
In fact, I want to show all the offices available for a user on a unique page including offices managed by single actions. How is this possible ?
Thank you in advance !
PS: Actions are in different controllers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我没听错的话。
我认为这听起来像是用户的权限问题。如果是的话,我推荐Ryan的宝石“CanCan”。它非常容易使用。
CanCan
及其 Railscast:#192 CanCan 授权
If I got you right.
I think it sounds like a user's privilege problem. If it is, I recommend Ryan's gem "CanCan". It's super easy to use.
CanCan
And its Railscast: #192 Authorization with CanCan
建立一个具有角色权重的指挥链。最重的角色融合了许多以某种方式相关的小角色。
Make a chain of command, with role-weights. The heaviest role merges a lot of somehow related small ones.
尝试 Cancan gem,它有一种基于角色限制数据库操作的方法。
docs 中的示例:
@articles = Article.accessible_by(current_ability)
Try the Cancan gem which has a way of constraining database operations based on roles.
Example from docs:
@articles = Article.accessible_by(current_ability)