This is what happens when I call "accessible_by". #246

Closed
HuckyDucky opened this Issue Jan 19, 2011 · 8 comments

Comments

Projects
None yet
3 participants

undefined method `table_name' for nil:NilClass

cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:38:in `tableized_conditions'
i18n (0.5.0) lib/i18n/backend/base.rb:37:in `inject'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:36:in `each'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:36:in `inject'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:36:in `tableized_conditions'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:39:in `tableized_conditions'
i18n (0.5.0) lib/i18n/backend/base.rb:37:in `inject'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:36:in `each'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:36:in `inject'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:36:in `tableized_conditions'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:29:in `conditions'
i18n (0.5.0) lib/i18n/backend/base.rb:37:in `inject'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:28:in `each'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:28:in `inject'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:28:in `conditions'
cancan (1.5.0) lib/cancan/model_adapters/active_record_adapter.rb:58:in `database_records'
cancan (1.5.0) lib/cancan/model_additions.rb:23:in `accessible_by'
app/controllers/brands_controller.rb:25:in `index'

I get this error too in an app with 1.5.0.

Fwiw, the error does not happen with 1.4.1.

I narrowed it down to the line in my Ability class that was causing the problem. It was like this:

  can :read, Brand, :responsibilities => { :user_id => user.id, :role => { :name => rolenames } }

When I changed that line to a block, and used :brand instead of Brand, like so:

  can :read, :brand do |brand|
    brand.responsibilities.where(:user_id => user.id, :role => { :name => rolenames }).first
  end

Then it worked correctly. But the error message is not indicative of what's going on.

BTW the only way I was able to troubleshoot this was to delete little bits of the Ability class until the code worked, then looked at what I deleted.

Owner

ryanb commented Jan 20, 2011

Thanks for reporting this. I think I see what the issue is. I'll work on getting a fix asap.

Owner

ryanb commented Jan 20, 2011

handle deeply nested conditions properly in active record adapter - closed by f9ad485

Wow, way to go! Thanks again Ryan.

Ryan, thank you for fixing this so quickly. Upgrading to 1.5.1 indeed solves the problem.

yan13to pushed a commit to paupauorg/cancan that referenced this issue May 30, 2017

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment