![](/img/trans.png)
[英]How to understand load_resource and authorize_resource methods of cancancan gem?
[英]how to use gem cancancan in layouts/application (in rails) ? it doesn't has controller to add authorize_resource?
如何在布局/應用程序(軌道)中使用gem cancancan? 它沒有控制器來添加authorize_resource嗎? 我想使用cancancan和rolify來管理布局/應用程序導航。
它不需要將authorize_resource添加到控制器。
只需添加一些代碼:(app / views / layouts / application.html.erb)
應用程序/模型/ ability.rb
Ability類包括CanCan :: Ability
def initialize(user)如果user.blank? 不能:管理,:全部
elsif user.has_role? :admin可以:manage,:所有結束
然后,只有角色為“ admin”的用戶才能看到(yeild)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.