** DBの調整をする [#ea3b289d]
- 設定ファイルを変更します
$ vi config/database.yml
production:
adapter: mysql
database: <DB名>
username: <DBへのユーザ名>
password: <DBへのパスワード>
socket: <sockへのパス>
- DBを作ります
$ mysql -utest_arena -p
mysql> CREATE DATABASE hogehoge_production DEFAULT CHARACTER SET utf8;
- migrateをかけます
$ rake environment RAILS_ENV=production migrate
** 設定ファイルを変更する [#w7c00700]
- production用の設定を確認します
$ vi config/environments/production.rb
↑config/environments/development.rbから必要な要素を追加
- 共通設定を変更します
$ vi config/environment.rb
ENV['RAILS_ENV'] ||= 'production'
↑コメントを取る
以上の作業で、アプリにアクセスするとDBがproduction側を向くようにはなりました。
# Webサーバの再起動は必要ないのだろうか…
** 動かしてみる [#l79204fa]
とりあえず、そのままアプリで、「会員を追加する」という
ストーリーを実行してみると、完了画面で↓このようなエラーが出ます。
COLOR(red):We're sorry, but something went wrong.
COLOR(red):We've been notified about this issue and we'll take a look at it shortly.
これはRailsのエラーだと思いますので、log/production.logを確認したところ、
送信するメールの本文と、その下に↓このようなエラーがありました。
Errno::ECONNREFUSED (Connection refused - connect(2)):
/usr/local/lib/ruby/1.8/net/protocol.rb:206:in `initialize'
/usr/local/lib/ruby/1.8/net/protocol.rb:206:in `new'
/usr/local/lib/ruby/1.8/net/protocol.rb:206:in `old_open'
/usr/local/lib/ruby/1.8/timeout.rb:56:in `timeout'
/usr/local/lib/ruby/1.8/timeout.rb:76:in `timeout'
/usr/local/lib/ruby/1.8/net/protocol.rb:206:in `old_open'
/usr/local/lib/ruby/1.8/net/smtp.rb:393:in `do_start'
/usr/local/lib/ruby/1.8/net/smtp.rb:378:in `start'
/usr/local/lib/ruby/1.8/net/smtp.rb:316:in `start'
/home/.../lib/action_mailer_plus.rb:50:in `perform_delivery_smtp'
/usr/local/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/action_mailer/base.rb:451:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/action_mailer/base.rb:451:in `deliver!'
/usr/local/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/action_mailer/base.rb:333:in `method_missing'
/home/.../app/controllers/member/reservations_controller.rb:75:in `create'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:1101:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:1101:in `perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/filters.rb:696:in `call_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/filters.rb:688:in `perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/rescue.rb:83:in `perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:435:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:435:in `process_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/filters.rb:684:in `process_without_session_management_support'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/session_management.rb:114:in `process'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:334:in `process'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/dispatcher.rb:41:in `dispatch'
/home/.../htdocs/dispatch.cgi:10
productionモードでメールが送れない? と思ってググったら、設定ファイルの問題らしい。
** 設定変更 [#jb7ec2f7]
config/environments/production.rbの
↓この設定がコメントアウトされていたが、
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
↓このように false を指定すれば動いた
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = false
とりあえず、いまは正常に動いているように見えます。
以上です。