Discussion:
i've been in activeadmin hell...
Patrick J. Collins
2012-04-06 17:21:40 UTC
Permalink
I am working on a project that uses active_admin, and I found once
building out all of the admin resource files, running rspec causes the
following error:

/Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /Users/patrick/coding/rails/foobar/app/admin/users.rb to define Users (LoadError)
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:190:in `each'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:190:in `const_missing'
from /Users/patrick/coding/rails/foobar/app/controllers/users/confirmations_controller.rb:1:in `<top (required)>'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:359:in `require_or_load'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:313:in `depend_on'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:225:in `require_dependency'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/engine.rb:438:in `each'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/engine.rb:438:in `block in eager_load!'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/engine.rb:436:in `each'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/engine.rb:436:in `eager_load!'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `run'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `each'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/application.rb:136:in `initialize!'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/patrick/coding/rails/foobar/config/environment.rb:5:in `<top (required)>'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/coding/rails/foobar/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/coding/rails/foobar/spec/controllers/locations_controller_spec.rb:1:in `<top (required)>'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /Users/patrick/.rvm/gems/ruby-1.9.3-***@foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'


... Changing the filename app/admin/users.rb to app/admin/wtfs.rb

makes this error go away... so--- wtfs indeed!

incidentally if you are wondering what is this business with
confirmations_controller (in the stack trace), that just inherits from Devise:

class Users::ConfirmationsController < Devise::ConfirmationsController
end


Patrick J. Collins
http://collinatorstudios.com
Justin Ko
2012-04-06 18:38:41 UTC
Permalink
Post by Patrick J. Collins
I am working on a project that uses active_admin, and I found once
building out all of the admin resource files, running rspec causes the
from /Users/patrick/coding/rails/foobar/app/controllers/users/confirmations_controller.rb:1:in `<top (required)>'
from /Users/patrick/coding/rails/foobar/config/environment.rb:5:in `<top (required)>'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/coding/rails/foobar/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/patrick/coding/rails/foobar/spec/controllers/locations_controller_spec.rb:1:in `<top (required)>'
... Changing the filename app/admin/users.rb to app/admin/wtfs.rb
makes this error go away... so--- wtfs indeed!
incidentally if you are wondering what is this business with
class Users::ConfirmationsController < Devise::ConfirmationsController
end
Patrick J. Collins
http://collinatorstudios.com
_______________________________________________
rspec-users mailing list
http://rubyforge.org/mailman/listinfo/rspec-users
I'm pretty sure this is an issue with how Rails autoloads things, I've run into it a few times. Checkout this post:

http://stackoverflow.com/questions/4074830/adding-lib-to-config-autoload-paths-in-rails-3-does-not-autoload-my-module
Patrick J. Collins
2012-04-06 19:40:10 UTC
Permalink
Post by Patrick J. Collins
... Changing the filename app/admin/users.rb to app/admin/wtfs.rb
makes this error go away... so--- wtfs indeed!
Well what doesn't make sense to me, is that I would expect having a file
called wtfs.rb should give a similar error expecting "Wtfs" to be
defined... But it doesn't..

Patrick J. Collins
http://collinatorstudios.com
Justin Ko
2012-04-06 19:53:21 UTC
Permalink
Post by Patrick J. Collins
Post by Patrick J. Collins
... Changing the filename app/admin/users.rb to app/admin/wtfs.rb
makes this error go away... so--- wtfs indeed!
Well what doesn't make sense to me, is that I would expect having a file
called wtfs.rb should give a similar error expecting "Wtfs" to be
defined... But it doesn't..
In Ruby, if you define a namespace class without defining the top-level class first, you'll get an error:

1.9.3p125 :001 > class Foo::Bar; end
NameError: uninitialized constant Foo
from (irb):1
from /Users/justinko/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'

So as you can see from your backtrace, the error is generating from confirmations_controller.rb, which makes sense because it has "class Users::ConfirmationsController".

If you look further up the backtrace, you'll see activesupport trying to handle that error with its `load_missing_constant` method. I assume it "searched" for a file named "users", because the constant was named "Users". WTF doesn't cause an error, because activesupport doesn't look for it.

Try renaming your namespace from "Users" to "User", which is a more appropriate name IMO.
Post by Patrick J. Collins
Patrick J. Collins
http://collinatorstudios.com
_______________________________________________
rspec-users mailing list
http://rubyforge.org/mailman/listinfo/rspec-users
Patrick J. Collins
2012-04-06 20:01:45 UTC
Permalink
Post by Justin Ko
So as you can see from your backtrace, the error is generating from confirmations_controller.rb, which makes sense because it has "class Users::ConfirmationsController".
If you look further up the backtrace, you'll see activesupport trying to handle that error with its `load_missing_constant` method. I assume it "searched" for a file named "users", because the constant was named "Users". WTF doesn't cause an error, because activesupport doesn't look for it.
Aha.. now it all makes sense...

Patrick J. Collins
http://collinatorstudios.com

Loading...