rails/rails — Issue #5148: lazy loading of ActiveResource model causes namespacing issues
Author: anikkar
Created: 2012-02-23 22:55:17+00:00
State: open

I've encountered a new issue when running in development in Rails 3.2.1 (which did not occur in Rails 2.3). If I have an ActiveResource model consuming an API that has the following response:

Company Name

Employee 1

Manager

The class names are namespaced if they have not been loaded yet (i.e. Object.const_defined? is returning false in ActiveResource.find_or_create_resource_for):

Company
Company::Employee
Company::Employee::Position

Its a hack, but to get around this, I added the following to one of my initializers:

Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require_dependency file }

Afterwards, the classes are correctly found:

Company
Employee
Position

This is critical in that link_to helpers dont work when the class names are namespaced.