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.

rails runner uninitialized constant Object

#4255

rails runner doesn't seem to be aware of objects in the rails environment anymore

% rails myapp
% cd myapp
% rails g scaffold post title:string body:text published:boolean
# edit a.rb
% cat a.rb
puts Rails.root
puts Post.count
% rails runner a.rb
a.rb:1:in `': uninitialized constant Object::Rails (NameError)
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands/runner.rb:43:in `eval'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands/runner.rb:43:in `'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands.rb:60:in `require'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands.rb:60:in `'
        from /private/tmp/myapp/script/rails:10:in `require'
        from /private/tmp/myapp/script/rails:10:in `'

Reported by trevor · March 23rd, 2010 @ 12:33 AM

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

Activity

  1. trevor
    trevor
    % rails -v
    Rails 3.0.0.beta
    

    March 23rd, 2010 @ 12:34 AM

  2. trevor
    trevor
    • Tag set to rails3 runner

    March 23rd, 2010 @ 12:34 AM

  3. moresheth
    moresheth

    It looks like someone has a fix for this:
    http://github.com/rails/rails/commit/39ebd6eb2b6c90756514798450eb15...

    Since trying to re-install the Rails 3 beta didn't work, and I'm not sure if there's an easy way to patch it from that commit, I just made the changes myself. The location of the files depends on where your ruby is installed, so on one machine, these were the files that I changed:

    /var/lib/gems/1.8/gems/railties-3.0.0.beta/lib/rails/commands.rb
    /var/lib/gems/1.8/gems/railties-3.0.0.beta/lib/rails/commands/runner.rb
    

    On another, it was these:

    /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta/lib/rails/commands.rb
    /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta/lib/rails/commands/runner.rb
    

    You're just moving the "require ENV_PATH" line.

    March 25th, 2010 @ 09:32 AM

  4. José Valim
    José Valim
    • Milestone cleared.
    • State changed from new to resolved

    March 26th, 2010 @ 12:06 AM

  5. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM