server build
development server build command
rake db:migrate
rails s -p $PORT -b $IP
protenction server build commands
rake db:migrate RAILS_ENV=production
rake assets:clean RAILS_ENV=production
rake assets:precompile RAILS_ENV=production
RAILS_SERVE_STATIC_FILES=true rails s -p $PORT -b $IP -e production
railsをWeblickサーバーで、production環境でサーバーを立てても、public/asstsを読み込んでくれない。
development環境なら、問題なく動作する。
これの原因は、config/environments/production.rb
の中の
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
の部分である。
どうやら、config.serve_static_files
の部分にtrue
がわたることによって、public/assets
を読み込んでくれる。理由はわからない。
ENV['RAILS_SERVE_STATIC_FILES']
の記述からわかるように、
export RAILS_SERVE_STATIC_FILES=true
でも同様に動作する。
なお、railsの方では、変数が存在しているか確認しているだけなので、
export RAILS_SERVE_STATIC_FILES=false
でも、同様の挙動を示す。
以前の環境に戻すには、
unset RAILS_SERVE_STATIC_FILES
をしてあげる必要がある。
devise install時、参考にしたdevise.ja.yml
https://gist.github.com/yhara/606476
http://easyramble.com/rails-devise-ja-yml.html (こっちの方がよさそう)
rails_secret_token をデプロイ時に自動生成する、スクリプト
http://railstutorial.jp/chapters/static-pages?version=4.0
の「リスト 3.2 秘密トークンを動的に生成する。」
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
require 'securerandom'
def secure_token
token_file = Rails.root.join('.secret')
if File.exist?(token_file)
# Use the existing token.
File.read(token_file).chomp
else
# Generate a new token and store it in token_file.
token = SecureRandom.hex(64)
File.write(token_file, token)
token
end
end
SampleApp::Application.config.secret_key_base = secure_token
SampleAppの部分は、適宜自分のアプリケーション名に変更してください
railsのタイムゾーンについて
railsのアプリを開発していると、ローカルタイムがアメリカにやヨーロッパになっていたりした時があったので、それの変更方法
- http://ruby-rails.hatenadiary.com/entry/20141217/1418817120#activesuppor-time-all-and-local-timezones
- http://yamacent.hatenablog.com/entry/2015/04/24/172148
- http://b.pyar.bz/blog/2014/10/27/rails-timezone/
-
http://kanonji.info/blog/2014/08/12/utc%E3%81%AA%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%81%A8mysql%E3%81%A8%E3%81%A7%E4%BD%BF%E3%81%86rails%E3%81%AE%E6%99%82%E9%96%93%E3%81%AE%E6%89%B1%E3%81%84%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6/
この辺りが参考になる。
具体的方法は、
module Workspace
class Application < Rails::Application
config.time_zone = 'Tokyo'
config.i18n.default_locale = :ja
end
end
のように、time_zone
と、default_locale
に書き換えること。
それと、
http://weblabo.oscasierra.net/centos6-timezone-1/
にあるように、OS自体のタイムゾーンも変更する必要があるみたい。
cp /usr/share/zoneinfo/Japan /etc/localtime
実行すると、railsがjapan/Tokyoで認識してくれる。