Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Runner throwing: undefined local variable or method `app' for main:Object (NameError)

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

like image 505
KKK Avatar asked Oct 14 '11 13:10

KKK


1 Answers

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.

like image 71
reectrix Avatar answered Nov 14 '22 23:11

reectrix