- Rails.application.configure do
- config.cache_classes = false
- config.eager_load = false
- config.consider_all_requests_local = true
- if Rails.root.join('tmp', 'caching-dev.txt').exist?
- config.action_controller.perform_caching
- config.action_controller.enable_fragment_cache_logging
- config.cache_store = :memory_store
- config.public_file_server.headers
- config.active_storage.service = :local
- config.action_mailer.raise_delivery_errors = false
- config.action_mailer.perform_caching = false
- config.active_support.deprecation = :log
- config.active_record.migration_error = :page_load
- config.active_record.verbose_query_logs = true
- config.assets.debug = true
- config.assets.quiet = true
- config.file_watcher = ActiveSupport::EventedFileUpdateChecker
以下はデフォルトのdevelopment.rbの記述である。
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Suppress logger output for asset requests. config.assets.quiet = true # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker end
Rails.application.configure do
application、configureについてはrails.rbで定義されている。
config.cache_classes = false
リクエストごとにアプリケーションのクラスやモジュールを再読み込みするか否かの設定。
(=キャッシュするか否か)
デフォルトではfalseのため、本番・テスト環境と比較すると動作は遅い。
ただし、コードの反映は即時実行される。
config.eager_load = false
設定したnamespaceを読み込むかどうかの設定。
trueにする場合は、config.eager_load_namespaces
に設定したnamespaceを読み込む。
config.eager_load_namespaces
はデフォルトでは記述されていない。(config.eager_loadがfalseであるから、当然である。)
config.consider_all_requests_local = true
エラーが発生したときに、エラー画面を表示するかどうかの設定。
trueの場合
(画像は移行時にロストパージしました)
falseの場合
(画像は移行時にロストパージしました)
if Rails.root.join('tmp', 'caching-dev.txt').exist?
chaching-dev.txtはデフォルトでは存在しないため、初期は以下の設定が適用される。
config.cache_store = :null_store
config.action_controller.perform_caching
コントローラーのキャッシュをアプリで使用するか否か。
config.action_controller.enable_fragment_cache_logging
フラグメントキャッシュのログを冗長ログで出力するか否か。
フラグメントキャッシュとは、ビューに関するキャッシュを示します。
config.cache_store = :memory_store
キャッシュストア(=キャッシュの保存場所)の設定。
- :memory_store(rubyプロセス内のメモリに保存)
- :file_store(ファイルに保存。パスを設定する必要がある。)
- :mem_cache_store(サーバーに保存)
- :null_store(保存しない)
config.public_file_server.headers
Cache-Controlの設定
config.active_storage.service = :local
Active Storageの画像の保存先の設定。
保存先はstorage.ymlで定義している。
test: service: Disk root: <%= Rails.root.join("tmp/storage") %> local: service: Disk root: <%= Rails.root.join("storage") %>
config.action_mailer.raise_delivery_errors = false
メーラーが失敗した時(=メールの配信が行われなかった時)、エラーを発生させるかどうか。
config.action_mailer.perform_caching = false
メーラーでフラグメントキャッシュを有効にするかどうか。
config.active_support.deprecation = :log
環境に対する非推奨レポート出力をどの形式で行うかの設定。
- :log
- :notify
- :stderr
config.active_record.migration_error = :page_load
マイグレーションができていない場合、エラー画面を表示するかどうか。
config.active_record.migration_error = :page_loadの場合
(画像は移行時にロストパージしました)
config.active_record.migration_error = falseの場合
(画像は移行時にロストパージしました)
config.active_record.verbose_query_logs = true
ログの出力方法が変わる。
trueの場合は記述の該当箇所を表示してくれる。
trueの場合
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 4 ORDER BY `users`.`id` ASC LIMIT 1 User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 4 ORDER BY `users`.`id` ASC LIMIT 1 ↳ app/views/posts/index.html.erb:1 Post Load (0.4ms) SELECT `posts`.* FROM `posts` Post Load (0.5ms) SELECT `posts`.* FROM `posts` ↳ app/views/posts/index.html.erb:12
falseの場合
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 4 ORDER BY `users`.`id` ASC LIMIT 1 ↳ app/views/posts/index.html.erb:1 Post Load (0.4ms) SELECT `posts`.* FROM `posts`
config.assets.debug = true
アセットコンパイル関係。
trueの場合、application.css以外に個別のcssファイル(jsファイル)を読み込む。
falseの場合、application.cssしか読み込まなくなる。
falseの場合はcssの変更が反映されなくなってしまうため、開発環境ではデフォルトのtrueのままにしておくのがベター。
config.assets.quiet = true
app/assetsに関するログの表示の設定。
app/assetsへのアクセスログが邪魔な場合はfalseにしよう。
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
ファイルの変更(更新)の検知についての記述。
各種設定を変更した際に、サーバーの再起動が必要になるか否かが決まる。
この記述を設定することで、設定ファイルを変更した際にサーバーを再起動する必要がなくなる。