LoginSignup
3
5

More than 5 years have passed since last update.

Railsプロジェクト新規作成時に毎回やること

Last updated at Posted at 2018-06-07
  • gemの導入
    • pry-rails
    • config
  • タイムゾーンをJSTに
config/application.rb
    config.time_zone = 'Tokyo'
    config.active_record.default_timezone = :local
  • productionのログレベルを変更
config/environments/production.rb
config.log_level = :warn
  • not foundのログを別ファイルに出すようにする
config/route.rb
    # Not Foundのときログにスタックトレースを残さないようにするため
    # https://stackoverflow.com/a/39289253/5209556
    match '*any' => 'not_found#not_found', via: [:get, :post, :delete, :options, :put, :patch]
app/controllers/not_found_controller.rb
  class NotFoundController < ApplicationController
    # Not Foundだけ別ファイルにログを出す
    NotFoundLogger = Logger.new(Rails.root.join('log', 'not_found.log'))

    # Not Foundのときログにスタックトレースを残さないようにするため
    # https://stackoverflow.com/a/39289253/5209556
    def not_found
      NotFoundLogger.error(request.fullpath)
      render plain: '404 Not Found', status: :not_found
    end
  end
  • jbuilderのpartialのログが大量に出て邪魔なので、出さないようにする
config/application.rb
    # jbuilderのpartialのログが大量に出て邪魔なので、出さないようにする
    config.action_view.logger = nil
3
5
2

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
3
5