LoginSignup
71

More than 5 years have passed since last update.

railsのProductionで手動でPrecompileし直す

Last updated at Posted at 2017-02-12

背景

プロダクションで出たJSのエラーがローカルで再現できない場合に、JSファイルは、precompileされているのでどこでエラーがでているのか見定めるのが難しい。

そこで、Productionのコードにconsole.logなどを書いてどこのファイルは正常で、どこのファイルで死んでいるのかをチェックしたい。

もしも

単にDeployの際にPrecompileがうまく言ってないだけの場合は、capistranoを使っている場合以下のコマンドでprecompileを再試行することができる

bundle exec cap production deploy:assets:precompile

念のために、serverも再起動して確認。

# 再起動のrakeタスクは自分で作成する必要がある
bundle exec cap production unicorn:restart 

Productionサーバで手動でPrecompileし直す

  1. <path to app>/release/<最新のtimestamp>/app/assets/のファイルを編集する。

    1. 例: console.log 'aaaa.coffee start'など
  2. Precompileしたものを全て削除

    bundle exec rake assets:clobber RAILS_ENV=production
    
  3. precompileする(新しいdigest が割り振られる)

    bundle exec rake assets:precompile RAILS_ENV=production
    
  4. Webサーバを再起動

    sudo systemctl restart <rails_app>.service
    

これで、どこのファイルまで問題なく読まれて、どこで問題が置きたかを簡単に確かめられる。

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
71