0

我有一個問題,因爲Ruby on Rails 3.1上的Declarative_Authorization已經很多天了。 我想補充這對每個控制器的頂部:爲什麼Declarative_Authorization中的attribute_check沒有找到ID的

class UsersController < ApplicationController 

    # Verifies that the user is connected and/or authorized to access the methods 
    filter_access_to :all, :attribute_check => true 

    (...) 
end 

它讓我有這個在我的authorization_rules.rb

has_permission_on [:albums], :to => [:adding] do 
    if_attribute :group => { :user => is { user } } 
end 

但是當我添加:attribute_check => true我得到這個錯誤:

Couldn't find {Model} without an ID 

我完全迷失了,我從這顆寶石開始。

回答

0

您的用戶變量爲空,也許,這樣查找錯誤爲什麼它的空

+0

即使用戶變量被設置爲我有這個錯誤。消息可能是:無法找到沒有ID的照片。該消息是爲每個模型顯示的。 – Ludovic

+0

請發佈您的代碼如何設置變量 – Lichtamberg

+0

我有一個lib目錄名稱中的模塊:'authorizations.rb'。這個授權類有en實例變量@user。我只需編寫'Authorization.current_user = current_user'來設置變量。 gem有一個方法current_user設置變量@user。你知道這寶石嗎?這是一個非常難以理解的寶石... – Ludovic

0

我找到了竅門,只需添加這對控制器的頂部:

class Group 
    before_filter :set_group 
    (...) 
    protected 
    def set_group 
     @group = Group.find_by_slug(params[:slug]) 
    end 
end 
相關問題