Why the :attribute_check in Declarative_Authorization don't found ID's

258 Views Asked by At

I have a problem since many days with Declarative_Authorization on Ruby on Rails 3.1. I add this on the top of each controller :

class UsersController < ApplicationController

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

    (...)
end

It allows me to have this on my authorization_rules.rb:

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

But when I add :attribute_check => true I get this error :

Couldn't find {Model} without an ID

I'm totally lost, I was starting with this gem.

2

There are 2 best solutions below

2
On

Your user variable is null maybe, so find the error why its null

0
On

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