Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

uninitialized constant Rails::DeprecatedConstant::Rails (NameError)

#5487

Just upgraded to Ruby 1.9.2-p0 and the latest Rails rc2. The app was running fine with ruby 1.9.2-head and Rails rc1. It will not start and gives the following error when I issue the command:

rails s

→ rails s
=> Booting WEBrick => Rails 3.0.0.rc2 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting
/home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in const_missing_from_s3_library': uninitialized constant Rails::DeprecatedConstant::Rails (NameError)

from (eval):1:in `block in initialize'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/deprecation.rb:29:in `call'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/deprecation.rb:29:in `method_missing'
from /home/bruparel/rr_work/file_manager/config/initializers/load_lib_dir.rb:1:in `<top (required)>'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/engine.rb:200:in `each'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/engine.rb:200:in `block in <class:Engine>'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/initializable.rb:25:in `instance_exec'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/initializable.rb:25:in `run'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/initializable.rb:49:in `each'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/initializable.rb:49:in `run_initializers'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/application.rb:134:in `initialize!'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0.rc2/lib/rails/application.rb:77:in `method_missing'
from /home/bruparel/rr_work/file_manager/config/environment.rb:5:in `<top (required)>'
from /home/bruparel/rr_work/file_manager/config.ru:3:in `block in <main>'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
from /home/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
from /home/bruparel/rr_work/file_manager/config.ru:1:in `new'
from /home/bruparel/rr_work/file_manager/config.ru:1:in `<main>'

Do I need to regenrate the app with release candidate 2?

thanks.

Bharat

Reported by Bharat Ruparel · August 29th, 2010 @ 02:17 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Bharat Ruparel
    Bharat Ruparel

    Please ignore if you think this is not important.

    Here is what happened. My Rails 3 app in Release Candidate 1 with ruby 1.9.2-head from a month ago was working fine with the following initializer in config/initializers directory:

    Dir.glob( "#{ RAILS_ROOT }/lib/*.rb" ).each { |f| require f }

    After upgrading to Rails 3 Release candidate 2 with stable release of Ruby 1.9.2-p0, it won't start as I reported above. I changed the initializer code to read

    Dir.glob( "#{ Rails.root }/lib/*.rb" ).each { |f| require f }

    and it started fine and the tests pass.

    I think we need to publish a warning that the "old" style constants will cause Release candidate 2 to not start?

    Bharat

    August 29th, 2010 @ 02:42 AM

  2. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to needs-more-info
    • Importance changed from to Low

    Can you try using

      Dir.glob( "#{ RAILS_ROOT }/lib/*.rb" ).each { |f| require f }
    

    in a fresh RC 2 app? It didn't give any errors for me. I'm guessing this is an aws-s3-0.6.2 issue. But just to be sure can you check?

    August 29th, 2010 @ 12:41 PM

  3. Bharat Ruparel
    Bharat Ruparel

    Hello Rohit,
    The error is gone after I made the afore mentioned change. Rails 3 reandomly picks on aws-s3 or right_aws and reports the
    uninitialized constant Rails::DeprecatedConstant::Rails (NameError)
    error. I have googled around to find if there are any reported incidences of Rails 3 not playing well with these two gems but it is possible that I may have missed relevant information.
    How do you suggest that I check aws?
    Thanks.
    Bharat

    August 29th, 2010 @ 03:07 PM

  4. Deleted User
    Deleted User

    I can confirm this error. Its actually two things having to do with RAILS_ROOT. From deprecation.rb line 48:

      DeprecatedConstant.deprecate("RAILS_ROOT",           "Rails.root.to_s")
    

    First problem is when the proc on line 21 is called, it ends up as Rails::DeprecatedConstant::Rails which does not exist. So first change is:

      DeprecatedConstant.deprecate("RAILS_ROOT",           "::Rails.root.to_s")
    

    Same would apply to the other deprecated constants.

    Next the call to RAILS_ROOT call .to_path (at least from attachment fu, see attachment_fu.rb, line 4):

    @@tempfile_path      = File.join(RAILS_ROOT, 'tmp', 'attachment_fu')
    

    Calling to_path on a string blows up. So these changes fix the problem for me:

      DeprecatedConstant.deprecate("RAILS_ROOT",           "::Rails.root")
      DeprecatedConstant.deprecate("RAILS_ENV",            "::Rails.env")
      DeprecatedConstant.deprecate("RAILS_DEFAULT_LOGGER", "::Rails.logger")
    

    August 29th, 2010 @ 11:59 PM

  5. Bharat Ruparel
    Bharat Ruparel

    If you folks need to look at a real app. I just uploaded both Rails 2.3.8 and Rails 3.0RC2 versions of my app on Github.

    http://github.com/bruparel/file_manager238

    http://github.com/bruparel/file_manager3

    Bharat

    August 30th, 2010 @ 12:36 AM

  6. Neeraj Singh
    Neeraj Singh
    • State changed from needs-more-info to resolved

    @cfis The changes suggested by you are already there.

      DeprecatedConstant.deprecate("RAILS_ROOT",           "::Rails.root.to_s")
      DeprecatedConstant.deprecate("RAILS_ENV",            "::Rails.env")
      DeprecatedConstant.deprecate("RAILS_DEFAULT_LOGGER", "::Rails.logger")
    

    August 30th, 2010 @ 01:50 AM

  7. Deleted User
    Deleted User

    Neeraj - I see that the :: as been added, so that is good.

    But I was also saying this:

    DeprecatedConstant.deprecate("RAILS_ROOT", "::Rails.root.to_s")

    Should be this:

    DeprecatedConstant.deprecate("RAILS_ROOT", "::Rails.root")

    Notice the removal of "to_s"

    September 5th, 2010 @ 05:25 AM