I have the following folder structure:
- models/
- mappings/
- user.rb
- mapping.rb
- service.rb
- user.rb
- ...
In mappings/user.rb, I have the following:
module Mappings
class User < Mapping
end
end
And mapping.rb is:
class Mapping < ActiveRecord::Base
end
In config/application.rb, I am autoloading the models as follows:
config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/presenters)
Unfortunately, I am getting this load_missing_constant
error:
/home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:481:in `load_missing_constant': Unable to autoload constant User, expected /vagrant/app/models/mappings/user.rb to define it (LoadError)
Any help would be greatly appreciated. I'm not sure what I'm missing!
UPDATE:
Full trace:
16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:180:in
const_missing' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/inflector/methods.rb:238:in
const_get' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/inflector/methods.rb:238:inblock in constantize' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/inflector/methods.rb:236:in
each' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/inflector/methods.rb:236:ininject' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/inflector/methods.rb:236:in
constantize' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:552:inget' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:583:in
constantize' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise.rb:302:inget' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/mapping.rb:80:in
to' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/mapping.rb:75:inmodules' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/mapping.rb:92:in
routes' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/mapping.rb:159:indefault_used_route' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/mapping.rb:69:in
initialize' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise.rb:336:innew' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise.rb:336:in
add_mapping' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/rails/routes.rb:224:inblock in devise_for' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in
each' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:indevise_for' 16:53:48 jobs.1 | from /vagrant/config/routes.rb:93:in
block in ' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.9/lib/action_dispatch/routing/route_set.rb:344:ininstance_exec' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.9/lib/action_dispatch/routing/route_set.rb:344:in
eval_block' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.9/lib/action_dispatch/routing/route_set.rb:322:indraw' 16:53:48 jobs.1 | from /vagrant/config/routes.rb:1:in
' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:inload' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in
block in load' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:232:inload_dependency' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in
load' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/routes_reloader.rb:40:inblock in load_paths' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/routes_reloader.rb:40:in
each' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/routes_reloader.rb:40:inload_paths' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/routes_reloader.rb:16:in
reload!' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/routes_reloader.rb:26:inblock in updater' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/file_update_checker.rb:75:in
call' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/file_update_checker.rb:75:inexecute' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/routes_reloader.rb:27:in
updater' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/routes_reloader.rb:7:inexecute_if_updated' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application/finisher.rb:71:in
block in ' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/initializable.rb:30:ininstance_exec' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/initializable.rb:30:in
run' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/initializable.rb:55:inblock in run_initializers' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:226:in
block in tsort_each' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:348:inblock (2 levels) in each_strongly_connected_component' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:427:in
each_strongly_connected_component_from' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:347:inblock in each_strongly_connected_component' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in
each' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:incall' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in
each_strongly_connected_component' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:224:intsort_each' 16:53:48 jobs.1 | from /home/vagrant/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:205:in
tsort_each' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/initializable.rb:54:inrun_initializers' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application.rb:300:in
initialize!' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/railtie.rb:194:inpublic_send' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/railtie.rb:194:in
method_missing' 16:53:48 jobs.1 | from /vagrant/config/environment.rb:8:in<top (required)>' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in
require' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:inblock in require' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:232:in
load_dependency' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:inrequire' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/application.rb:276:in
require_environment!' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/commands/runner.rb:52:in<top (required)>' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:128:in
require' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:128:inrequire_command!' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:95:in
runner' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:40:inrun_command!' 16:53:48 jobs.1 | from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/railties-4.1.9/lib/rails/commands.rb:17:in
' 16:53:48 jobs.1 | from bin/rails:8:inrequire' 16:53:48 jobs.1 | from bin/rails:8:in
'
So it looks like the issue is because I have to classes named User
, even though one is namespaced inside a Module.
User
rather thanMappings::User
- it is however pretty weird as yourmappings
folder is not directly in the autoload path. Anything intersting in the initalizers? – BroiSatseMappings::User
. I also tried adding ` config.autoload_paths += Dir[Rails.root.join('app', 'models', 'mappings','{**}')]` but no success. – Adamrequire: false
next to a FactoryGirl gem in you Gemfile. Requiring it in a development causes all the models to be loaded on startup (factories are loaded). You should be able to load the console then. Tr to load your models then and find out which is raising this error. Check it for any associations with Mappings::User models which are called:users
- most likely you will need to addclass_name: 'Mappings::User'
to those. – BroiSatseUser
despite the fact that one is namespaced underMappings
. I figure it will be best to just rename it toUserMapping
. – Adam