Friday, July 29, 2011

Change RAILS_ROOT to Rails.root when upgrading to Rails 3

Getting following error while upgrading to Rails 3.1.0.rc5

NameError (uninitialized constant Search::RAILS_ROOT):
  app/models/search.rb:159:in `run'
  app/controllers/searches_controller.rb:66:in `new'

  Rendered highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
  Rendered highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
  Rendered highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (35.6ms)

Solution to fix the problem:

Change RAILS_ROOT to Rails.root

3 comments:

  1. thanks.. this helps me instantly..

    ReplyDelete
  2. Rails.root is working fine in controller. But it is giving me a error that " undefined method `root' ". Please help

    ReplyDelete
  3. Deepak, where it is giving error that " undefined method `root' " (in view, model, controller). Which version of rails you are using?

    ReplyDelete