Rails Runner抛出:未定义的局部变量或方法`app'for main:Object(NameError)

时间:2011-10-14 13:26:38

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

我有一个工作的Rails应用程序(3.1.1)。现在我写了一个跑步者(保存在app文件夹中)。 启动跑步者时: rails r app / delete_old_addresses.rb

它转储:

/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 method app'for main:Object(NameError)     来自/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'     来自/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'     来自script / rails:6:require' from script/rails:6:in'

任何想法为什么?我的Webapp工作得很好。

跑步者看起来像这样: class DeleteOldAddresses<的ActiveRecord :: Base的 端

1 个答案:

答案 0 :(得分:10)

我有同样的问题。在my_script.rb上运行rails runner(在我的脚本文件夹中,我在Rails 4.0.0中创建与app目录相同的级别)直接给了我这个错误。当我跑rails runner script/my_script.rb时它起作用了。