Ruby on Rails config configuration

This article notes the Rails 6.1 config settings.

config/application.rb

Set the time zone locally

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

config/puma.rb

Use localhost: 3000 for development and unix socket for production

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

Use redis for cache

  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}"
    }
  }

Use redis for sessions

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

Add gem to Gemfile to use redis with Rails

Gemfile


gem 'redis-rails'

config/webpacker.yml

If you are using webpack, can you detect html changes as well? The setting here needs to be considered

extensions:
...
  - .html
...

Recommended Posts

Ruby on Rails config configuration
Ruby on Rails Elementary
Ruby on Rails basics
Ruby On Rails Association
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
Ruby on Rails Overview (Beginner Summary)
[Ruby on Rails] Read try (: [],: key)
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
[Ruby on Rails] Introduced paging function
Basic knowledge of Ruby on Rails
Progate Ruby on Rails5 Looking Back
How to use Ruby on Rails
[Ruby on Rails] Add / Remove Columns
Ruby on Rails Japanese-English support i18n
(Ruby on Rails6) "Erase" posted content
[Ruby on Rails] CSV output function
Ruby on Rails 6.0 environment construction memo
[Ruby on Rails] What is Bcrypt?
[Ruby on Rails] Confirmation page creation
Ruby On Rails devise routing conflict
[Ruby on Rails] Comment function implementation
[Ruby on Rails] DM, chat function
[Ruby on Rails] Convenient helper method
[Ruby on Rails] Stop "looping until ..."
[Ruby on Rails] Introduction of initial data
[Ruby on Rails] Search function (not selected)
[Rails] Addition of Ruby On Rails comment function
[Ruby on Rails] Creating an inquiry form
Ruby on Rails6 Practical Guide cp13 ~ cp15 [Memo]
[Ruby on Rails] View test with RSpec
[Ruby on Rails] Code check using Rubocop-airbnb
[Ruby on Rails] 1 model CRUD (Routing Main)
Ruby on Rails installation method [Mac edition]
[Ruby on Rails] model, controller terminal command
Let's summarize "MVC" of Ruby on Rails
Ruby on Rails model creation / deletion command
[Ruby on Rails] About bundler (for beginners)
part of the syntax of ruby ​​on rails
Tailwind on Rails
Ruby on Rails6 Practical Guide cp7 ~ cp9 [Memo]
Ruby on Rails in Visual Studio Codespaces
[Ruby on Rails] Follow function implementation: Bidirectional
Notes on using FCM with Ruby on Rails
[Ruby on Rails] Controller test with RSpec
Deploy to Heroku [Ruby on Rails] Beginner
[Ruby on Rails] Image slideshow using Skippr
Ruby on Rails controller create / delete command
Preparing to introduce jQuery to Ruby on Rails
[Ruby on Rails] About Active Record callbacks