如何向通关宝石添加权限/角色?
我有基本的权限设置 -
rails generate clearance:install
在
rails generate clearance:views
我的 admin_controller 中,我有
before_filter :authorize
这可以确保用户已登录。我如何为我的用户设置“管理员”权限,并确保用户在允许他们进入管理控制器之前拥有该权限?
对此有更好的解决方案吗?
谢谢!
安德鲁
I have the basic clearance setup -
rails generate clearance:install
and
rails generate clearance:views
In my admin_controller, I have
before_filter :authorize
This makes sure the user is logged in. How would I setup 'admin' privileges on my users and make sure the user has the privlege before allowing them into the admin controller?
Is there a better solution for this?
Thanks!
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有同样的问题,但是
cancan
对我来说似乎太多了(小项目)实际上 源代码 非常简单,所以我的此处的方法:
在初始化程序中打开
Clearance::Authorization
模块,并在其中添加自定义方法:不要忘记重新启动服务器:)
i had the same question, but
cancan
seems too much for me (small project)Actually the source code of
authorize
is quite simple, so my approach here:open the
Clearance::Authorization
module in initializer, and add custom methods there:don't forget to restart the server :)
与 CanCan 混合
https://github.com/ryanb/cancan
http://railscasts.com/episodes/192-authorization-with-cancan
Mix it with CanCan
https://github.com/ryanb/cancan
http://railscasts.com/episodes/192-authorization-with-cancan