ryanb/cancan — Issue #526: Object is not missing constant
Author: fuelxc
Created: 2011-12-07 10:25:39+00:00
State: open

I have a namespaced controller and the lookup seems to be failing for some reason. I have gone round and round with the root cause but getting no where. I am unable to build a test for this scenario so I don't wich to submit a patch (without a test to prove the failure).

/gems/activesupport-2.3.12/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/gems/activesupport-2.3.12/lib/active_support/dependencies.rb:106:in `rake_original_const_missing'
/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in `const_missing'
/gems/activesupport-2.3.12/lib/active_support/dependencies.rb:118:in `const_missing'
/gems/activesupport-2.3.12/lib/active_support/dependencies.rb:124:in `send'
/gems/activesupport-2.3.12/lib/active_support/dependencies.rb:124:in `const_missing'
/gems/activesupport-2.3.12/lib/active_support/inflector.rb:364:in `constantize'
/gems/activesupport-2.3.12/lib/active_support/inflector.rb:363:in `each'
/gems/activesupport-2.3.12/lib/active_support/inflector.rb:363:in `constantize'
/gems/activesupport-2.3.12/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/gems/cancan-1.6.7/lib/cancan/controller_resource.rb:211:in `namespaced_name'
/gems/cancan-1.6.7/lib/cancan/controller_resource.rb:141:in `resource_class'
/gems/cancan-1.6.7/lib/cancan/controller_resource.rb:77:in `load_collection?'

I have a namespaced and non namespaced controller for a model
Account::ModelController < Account::Base
ModelController < ApplicationController

Model < ActiveRecord::Base

I actually have several models and they all throw the error for collections, but not resource

Not sure why it goes all the way to the Object class to check for a constant (this is where I get lost for the root cause). Patching the method namespaced_name to recover from both errors but just feels wrong.

Happy to help if you can point in the right direction.