0

自从在 Ruby on Rails 3.1 上使用 Declarative_Authorization 以来,我一直遇到问题。我在每个控制器的顶部添加了这个:

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

我完全迷路了,我是从这个宝石开始的。

4

2 回答 2

0

您的用户变量可能为 null,因此请找出错误原因为 null

于 2012-10-29T13:08:53.300 回答
0

I found the trick, just add this on the top of the controller :

class Group
    before_filter :set_group
    (...)
    protected
    def set_group
        @group = Group.find_by_slug(params[:slug])
    end
end
于 2012-10-29T21:09:14.107 回答