Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Autoloading models from external folder fails on Rails 3.1, 3.2 #5007

brodock opened this Issue · 5 comments

2 participants


What I'm basically doing is sharing some models across multiple projects. I have a base project where all models are defined and some other projects that requires thous models, as all of them use the same data.

By that said, what I used to do is define a config.autoload_paths pointing to the other projects model folder:

 config.autoload_paths += %W(#{config.root}/../base_project/app/models)

With Rails 3.0 it works perfectly fine, however with Rails 3.1, 3.2, I get uninitialized constnat to every model name, for example:

 NameError (uninitialized constant ApplicationController::User):
   app/controllers/application_controller.rb:11:in `current_user'

Does it work if you use File.expand_path?

Also another way of achieving what you want is to create an engine with your shared models and then using a :path spec in your Gemfile, e.g:

gem 'shared_models', :path => '/path/to/shared_models'

@pixeltrix I don't know if I'm doing it wrong but, using File.expand_path gave me:

 can't modify frozen Array

Here is the snipet:

 config.autoload_paths << File.expand_path( "#{config.root}/../base_project/app/models" )

The engine may became an alternative, but I still looking for a way to make Rails look for the shared models without using it.


@brodock you can't modify autoload_paths in place - use +=, e.g:

config.autoload_paths += [File.expand_path("#{config.root}/../base_project/app/models")]

@pixeltrix Ok, got it right this time, but still same result.


Okay I can confirm this works for me in 3.2.3 if you can provide any further information on how it's not working for you then I'll take another look at it. You don't need the File.expand_path but it doesn't work using star paths e.g. #"{config.root}/../shared/**/*" won't work.

@pixeltrix pixeltrix closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.