5
votes

I got a working Rails App (3.1.1). Now I wrote a runner (saved in app folder). When starting the runner with: rails r app/delete_old_addresses.rb

it dumps:

/Users/andreas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/commands/runner.rb:49:in eval': undefined local variable or methodapp' for main:Object (NameError) from /Users/andreas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/commands/runner.rb:49:in eval' from /Users/andreas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/commands/runner.rb:49:in' from /Users/andreas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/commands.rb:63:in require' from /Users/andreas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/commands.rb:63:in' from script/rails:6:in require' from script/rails:6:in'

Any ideas why? My Webapp works perfectly fine.

The runner looks like this: class DeleteOldAddresses < ActiveRecord::Base end

1
My bad, should be starting the runner with rails r app/runners/delete_old_addresses.rbKKK
Running with relative path might be an issue, try full path instead.Muhamed Huseinbašić

1 Answers

10
votes

I had the same issue. Running rails runner on my_script.rb (in my script folder, which I created on the same level as the app directory in Rails 4.0.0) directly gave me this error. When I ran rails runner script/my_script.rb it worked.