簡體   English   中英

康康采取新行動

[英]cancan for new action

我在我的restful資源中添加了新操作,如何使用cancan對其進行授權。

頁面控制器:

load_and_authorize_resource


 def index    
 end

 def show
 end

 def new
 end

 def create
 end

 def edit
 end

 def update
 end

 def destroy
 end 

 def mynewaction
 end

能力模型:

class Ability
  include CanCan::Ability

  def initialize(user)
      user ||= User.new
      can :create, Page
      can :mynewmethod, Page #does it work?

  end

是的我相信它適用於除CRUD方法之外的其他方法,雖然這只是查看一些文檔,請查看此處以及ryanb實際文檔

您應該特別注意第一個鏈接,該鏈接指出load_and_authorize_resource將應用於控制器中的所有方法,甚至是通常的CRUD之外的方法。

我認為最簡單的方法就是測試一下,當你啟動它時它是否正確授權? 沒有比嘗試更好的了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM