我遇到一个奇怪的问题,我的rake任务在我的本地机器上运行但不在生产中。在PRODUCTION中尝试相同时出现以下错误
rake aborted!未初始化的常量User :: UserGroup
当我在其上运行跟踪得到以下输出
$ RAILS_ENV =生产包exec rake billing:invoices --trace
** Invoke billing:invoices (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute billing:invoices
Building invoices
rake aborted!
uninitialized constant User::UserGroup
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/base.rb:1205:in `compute_type'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/reflection.rb:162:in `klass'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:2107:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:1984:in `new'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:1984:in `build_join_association'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:1948:in `build'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:1956:in `block in build'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:1955:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:1955:in `build'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/associations.rb:1852:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/relation/query_methods.rb:246:in `new'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/relation/query_methods.rb:246:in `build_joins'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/relation/query_methods.rb:176:in `build_arel'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/relation/query_methods.rb:149:in `arel'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/relation/batches.rb:51:in `find_in_batches'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.11/lib/active_record/relation/batches.rb:20:in `find_each'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p327/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p327/bin/rake:23:in `<main>'
Tasks: TOP => billing:invoices
奇怪的是它在我的本地机器上工作正常。有什么建议吗?
答案 0 :(得分:1)
我的猜测是你刚刚添加了一个名为20120221123456_users.rb
的迁移,在其中,你有:
class SomeNameThatsNotUsers < ActiveRecord::Migration
...
当Rails执行迁移时,它期望执行定义类的文件,然后实例化该类,并在该类实例上调用#up或#down。 Rails如何知道要实例化的类?它应该与数字前缀和下划线后面的文件名部分相对应,因此对于像20120221123456_users.rb
这样的文件名,类名必须是Users
。
答案 1 :(得分:0)
您可以放置失败的rake任务源代码吗?
通常你需要写这样的东西(以避免AR出现问题):
desc“我的任务描述” 任务:my_task_name =&gt; :环境呢 #任务代码在这里 端