LoginSignup
1
0

More than 3 years have passed since last update.

Ruby on Railsのconfig設定

Last updated at Posted at 2021-01-18

この記事ではRails6.1のconfig設定をメモしています。

config/application.rb

タイムゾーンをローカルに設定する

config.time_zone = 'Tokyo'
config.active_record.default_timezone = :local

config/puma.rb

developmentではlocalhost:3000、productionではunix socketを使用する

if ENV.fetch("RAILS_ENV", "development") == 'production'
  bind "unix://#{Rails.root}/tmp/sockets/puma.sock"
else
  port ENV.fetch("PORT") { 3000 }
end

config/environments/production.rb

キャッシュにredisを使用する

  cache_servers = %w(redis://localhost:6379/1)
  config.cache_store = :redis_cache_store, {
    url: cache_servers,
    connect_timeout: 30,
    read_timeout: 0.5,
    write_timeout: 0.5,
    reconnect_attemps: 1,
    error_handler: -> (method:, returning:, exception:){
      Rails.logger.warn "exception: #{exception}, method: #{method}, returning: #{returning}"
    }
  }

セッションにredisを使用する

  config.session_store :redis_store,
    servers: [{
      host: 'localhost',
      port: 6379,
      db: 0,
      namespace: 'sessions',
    }],
    key: "_session_name_",
    expire_after: 30.minutes

Railsでredisを使用するためGemfileにgemを追加する

Gemfile
gem 'redis-rails'

config/webpacker.yml

webpackを使用している場合はhtmlの変更も検知できるようにする?
ここの設定は検討が必要

extensions:
...
  - .html
...
1
0
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
0