herokuへRails4アプリをデプロイする際の注意点

Last-modified: Sat, 02 Aug 2014 09:03:16 JST (3556d)
Top > herokuへRails4アプリをデプロイする際の注意点

herokuへRails4アプリをデプロイする際の注意点

  1. Heroku Toolbeltをインストール
    wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
    なお、
    http://toolbelt.heroku.com ./ Release.gpg         
    というエラーが出た場合は、FWとかプロクシとかアンチウイルスが原因らしいので、切ってみる。
  2. Herokuへログインする
    heroku login
    最終的に
    Authentication successful.
    と出ればOK。
  3. Gemfileに下記内容を追記し、bundle installする。
    gem 'rails_12factor', :group => [:production]
  4. Herokuはsqliteが使えないので、postgresqlを使う。Gemfileに下記追記し、bundle installする。
    gem 'pg', :group => [:production]
  5. database.ymlのproductionには以下のような感じで設定
    production:
     adapter: postgresql
     encoding: utf8
     database: <DB名>
     username: <ユーザ名>
     password: <パスワード>
     host: <接続先>
    • なお、postgresqlの追加はHerokuのアプリケーションのadd-onsからheroku postgresをクリックして追加する。 追加したら、connectionsettingsの画面で設定内容が見れる。
  6. deviseを使っている場合は、production.rbに下記追記
    config.action_mailer.default_url_options = { :host => 'self-ca.herokuapp.com' }
  7. production.rbより
    config.assets.precompile
    のコメントを外す。
    bundle exec rake assets:precompile
    を実行。

herokuへデプロイするとCSSやJSが読み込まれない

Gemfileに

gem 'rails_12factor', :group => [:production]

を追記し、

bundle exec rake assets:precompile

でローカルの開発環境でプリコンパイルしたものをプッシュするとうまくいく。
http://stackoverflow.com/questions/10215416/javascript-features-work-on-localhost-but-not-when-deployed-to-heroku?lq=1


Counter: 435, today: 2, yesterday: 0

このページの参照回数は、435です。