LoginSignup
1
1

More than 5 years have passed since last update.

RakeタスクでModelがNameErrorになる

Last updated at Posted at 2015-04-24

現象

[ec2-user@Test railsapp]$ RAILS_ENV=production rake user:task
rake aborted!
NameError: uninitialized constant User
...

原因

productionの初期設定だとモデルファイルが事前に読み込まれないのが問題のようです。

対処法

production.rb 設定ファイルに次の2行を追加する。

config/environments/production.rb
  config.threadsafe!
  config.dependency_loading = true if $rails_rake_task

念のため、Rakeタスクファイルに次の1行を追加する。

lib/tasks/export.rake
  $rails_rake_task = true

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1