views:

110

answers:

3

I have a data model which has the name 'rack'. When I generate a model with this name in my Rails project, I get errors when launching the server.

load_missing_constant: uninitialized constant ActiveRecord (NameError)

I am not using Rack Middleware and I don't see 'rack' as a reserved word in Ruby or Rails. Is there something I'm missing here?

A: 

Did you change your config/environment.rb file to remove ActiveRecord?

Rails::Initializer.run do |config|
  #...

  # Skip frameworks you're not going to use. To use Rails without a database,
  # you must remove the Active Record framework.
  config.frameworks -= [ :active_record ]

  #...
end
Garrett
A: 

What version of rails are you running?

As of 2.3, rails runs on Rack

klochner
+2  A: 

Well, if you're using a recent version of Rails, you actually are using Rack middleware, since that's how several Rails components are implemented these days (Rails as a whole is, in fact, a Rack application now). As such, there's already a constant named Rack, so when you try to create an ActiveRecord model called Rack, there's a collision. I'm not sure why you get that particular error, though - when I tried it on a toy project, I got this error trying to run the migration:

jhyland@john-hylands-macbook: ~/tmp/foo $ rake db:migrate
(in /Users/jhyland/tmp/foo)
rake aborted!
Rack is not a module

Regardless, I strongly suspect that this is the underlying cause of your problem. Would it be possible to change the name of your model?

John Hyland
Name collisions cause all kinds of strange errors: http://stackoverflow.com/questions/960781/rails-cannot-find-model-with-same-name-as-ruby-class
Sarah Mei