Skip to content

Commit 0ef18cd

Browse files
committed
Rails8: update Rails config
1 parent 6d7d6db commit 0ef18cd

File tree

18 files changed

+700
-349
lines changed

18 files changed

+700
-349
lines changed

bin/dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env ruby
2+
exec "./bin/rails", "server", *ARGV

bin/rubocop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env ruby
2+
require "rubygems"
3+
require "bundler/setup"
4+
5+
# explicit rubocop config increases performance slightly while avoiding config confusion.
6+
ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__))
7+
8+
load Gem.bin_path("rubocop", "rubocop")

bin/setup

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33

44
require "fileutils"
55

6-
# path to your application root.
76
APP_ROOT = File.expand_path("..", __dir__)
87

98
def system!(*args)
109
system(*args, exception: true)
1110
end
1211

13-
FileUtils.chdir(APP_ROOT) do
14-
# This script is a way to set up or update your development environment
15-
# automatically. This script is idempotent, so that you can run it at any
16-
# time and get an expectable outcome. Add necessary setup steps to this file.
12+
FileUtils.chdir APP_ROOT do
13+
# This script is a way to set up or update your development environment automatically.
14+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
15+
# Add necessary setup steps to this file.
1716

1817
puts "== Installing dependencies =="
19-
system! "gem install bundler --conservative"
2018
system("bundle check") || system!("bundle install")
2119

2220
# puts "\n== Copying sample files =="
@@ -30,6 +28,9 @@ FileUtils.chdir(APP_ROOT) do
3028
puts "\n== Removing old logs and tempfiles =="
3129
system! "bin/rails log:clear tmp:clear"
3230

33-
puts "\n== Restarting application server =="
34-
system! "bin/rails restart"
31+
unless ARGV.include?("--skip-server")
32+
puts "\n== Starting development server =="
33+
STDOUT.flush # flush the output before exec(2) so that it displays
34+
exec "bin/dev"
35+
end
3536
end

bin/thrust

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
require "rubygems"
3+
require "bundler/setup"
4+
5+
load Gem.bin_path("thruster", "thrust")

config/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Stringer
2525

2626
class Stringer::Application < Rails::Application
2727
# Initialize configuration defaults for originally generated Rails version.
28-
config.load_defaults(7.1)
28+
config.load_defaults(8.0)
2929

3030
# Please, add to the `ignore` list any other `lib` subdirectories that do
3131
# not contain `.rb` files, or that should not be reloaded or eager loaded.

config/environments/development.rb

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
# Settings specified here will take precedence over those in
77
# config/application.rb.
88

9-
# In the development environment your application's code is reloaded any time
10-
# it changes. This slows down response time but is perfect for development
11-
# since you don't have to restart the web server when you make code changes.
9+
# Make code changes take effect immediately without server restart.
1210
config.enable_reloading = true
1311

1412
# Do not eager load code on boot.
@@ -17,53 +15,49 @@
1715
# Show full error reports.
1816
config.consider_all_requests_local = true
1917

20-
# Enable server timing
18+
# Enable server timing.
2119
config.server_timing = true
2220

23-
# Enable/disable caching. By default caching is disabled.
24-
# Run rails dev:cache to toggle caching.
21+
# Enable/disable Action Controller caching. By default Action Controller
22+
# caching is disabled. Run rails dev:cache to toggle Action Controller
23+
# caching.
2524
if Rails.root.join("tmp/caching-dev.txt").exist?
2625
config.action_controller.perform_caching = true
2726
config.action_controller.enable_fragment_cache_logging = true
28-
29-
config.cache_store = :memory_store
30-
config.public_file_server.headers = {
31-
"Cache-Control" => "public, max-age=#{2.days.to_i}"
32-
}
27+
config.public_file_server.headers =
28+
{ "cache-control" => "public, max-age=#{2.days.to_i}" }
3329
else
3430
config.action_controller.perform_caching = false
35-
36-
config.cache_store = :null_store
3731
end
3832

33+
# Change to :null_store to avoid any caching.
34+
config.cache_store = :memory_store
35+
3936
# Print deprecation notices to the Rails logger.
4037
config.active_support.deprecation = :log
4138

42-
# Raise exceptions for disallowed deprecations.
43-
config.active_support.disallowed_deprecation = :raise
44-
45-
# Tell Active Support which deprecation messages to disallow.
46-
config.active_support.disallowed_deprecation_warnings = []
47-
4839
# Raise an error on page load if there are pending migrations.
4940
config.active_record.migration_error = :page_load
5041

5142
# Highlight code that triggered database queries in logs.
5243
config.active_record.verbose_query_logs = true
5344

45+
# Append comments with runtime information tags to SQL queries in logs.
46+
config.active_record.query_log_tags_enabled = true
47+
5448
# Highlight code that enqueued background job in logs.
5549
config.active_job.verbose_enqueue_logs = true
5650

57-
# Suppress logger output for asset requests.
58-
config.assets.quiet = true
59-
6051
# Raises error for missing translations.
6152
# config.i18n.raise_on_missing_translations = true
6253

6354
# Annotate rendered view with file names.
64-
# config.action_view.annotate_rendered_view_with_filenames = true
55+
config.action_view.annotate_rendered_view_with_filenames = true
6556

6657
# Raise error when a before_action's only/except options reference missing
67-
# actions
58+
# actions.
6859
config.action_controller.raise_on_missing_callback_actions = true
60+
61+
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
62+
# config.generators.apply_rubocop_autocorrect_after_generate!
6963
end

config/environments/production.rb

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,74 @@
99
# Code is not reloaded between requests.
1010
config.enable_reloading = false
1111

12-
# Eager load code on boot. This eager loads most of Rails and
13-
# your application in memory, allowing both threaded web servers
14-
# and those relying on copy on write to perform better.
15-
# Rake tasks automatically ignore this option for performance.
12+
# Eager load code on boot for better performance and memory savings (ignored
13+
# by Rake tasks).
1614
config.eager_load = true
1715

18-
# Full error reports are disabled and caching is turned on.
19-
config.consider_all_requests_local = false
20-
config.action_controller.perform_caching = true
21-
22-
# Ensures that a master key has been made available in
23-
# ENV["RAILS_MASTER_KEY"], config/master.key, or an environment key such as
24-
# config/credentials/production.key. This key is used to decrypt credentials
25-
# (and other encrypted files).
26-
# config.require_master_key = true
16+
# Full error reports are disabled.
17+
config.consider_all_requests_local = false
2718

28-
# Enable static file serving from the `/public` folder (turn off if using
29-
# NGINX/Apache for it).
30-
config.public_file_server.enabled = true
31-
32-
# Compress CSS using a preprocessor.
33-
# config.assets.css_compressor = :sass
19+
# Turn on fragment caching in view templates.
20+
config.action_controller.perform_caching = true
3421

35-
# Do not fallback to assets pipeline if a precompiled asset is missed.
36-
config.assets.compile = false
22+
# Cache assets for far-future expiry since they are all digest stamped.
23+
config.public_file_server.headers = {
24+
"cache-control" => "public, max-age=#{Integer(1.year, 10)}"
25+
}
3726

3827
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
3928
# config.asset_host = "http://assets.example.com"
4029

41-
# Specifies the header that your server uses for sending files.
42-
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
43-
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
44-
4530
# Assume all access to the app is happening through a SSL-terminating reverse
46-
# proxy. Can be used together with config.force_ssl for
47-
# Strict-Transport-Security and secure cookies.
48-
# config.assume_ssl = true
31+
# proxy.
32+
config.assume_ssl = true
4933

5034
# Force all access to the app over SSL, use Strict-Transport-Security, and
5135
# use secure cookies.
5236
config.force_ssl = true
5337

54-
# Log to STDOUT by default
55-
logger = ActiveSupport::Logger.new($stdout)
56-
logger.formatter = Logger::Formatter.new
57-
config.logger = ActiveSupport::TaggedLogging.new(logger)
38+
# Skip http-to-https redirect for the default health check endpoint.
39+
# config.ssl_options =
40+
# { redirect: { exclude: ->(request) { request.path == "/up" } } }
5841

59-
# Prepend all log lines with the following tags.
42+
# Log to STDOUT with the current request id as a default log tag.
6043
config.log_tags = [:request_id]
44+
config.logger = ActiveSupport::TaggedLogging.logger($stdout)
6145

62-
# Info include generic and useful information about system operation, but
63-
# avoids logging too much information to avoid inadvertent exposure of
64-
# personally identifiable information (PII). If you want to log everything,
65-
# set the level to "debug".
46+
# Change to "debug" to log everything (including potentially
47+
# personally-identifiable information!)
6648
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
6749

68-
# Use a different cache store in production.
50+
# Prevent health checks from clogging up the logs.
51+
config.silence_healthcheck_path = "/up"
52+
53+
# Don't log any deprecations.
54+
config.active_support.report_deprecations = false
55+
56+
# Replace the default in-process memory cache store with a durable
57+
# alternative.
6958
# config.cache_store = :mem_cache_store
7059

71-
# Use a real queuing backend for Active Job (and separate queues per
72-
# environment).
73-
# config.active_job.queue_adapter = :resque
74-
# config.active_job.queue_name_prefix = "stringer_production"
60+
# Replace the default in-process and non-durable queuing backend for Active
61+
# Job.
62+
# config.active_job.queue_adapter = :resque
7563

7664
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
7765
# the I18n.default_locale when a translation cannot be found).
7866
config.i18n.fallbacks = true
7967

80-
# Don't log any deprecations.
81-
config.active_support.report_deprecations = false
82-
8368
# Do not dump schema after migrations.
8469
config.active_record.dump_schema_after_migration = false
8570

71+
# Only use :id for inspections in production.
72+
config.active_record.attributes_for_inspect = [:id]
73+
8674
# Enable DNS rebinding protection and other `Host` header attacks.
8775
# config.hosts = [
8876
# "example.com", # Allow requests from example.com
8977
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
9078
# ]
79+
#
9180
# Skip DNS rebinding protection for the default health check endpoint.
9281
# config.host_authorization =
9382
# { exclude: ->(request) { request.path == "/up" } }

config/environments/test.rb

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "active_support/core_ext/integer/time"
4-
53
# The test environment is used exclusively to run your application's
64
# test suite. You never need to work with it otherwise. Remember that
75
# your test database is "scratch space" for the test suite and is wiped
@@ -21,18 +19,16 @@
2119
# code.
2220
config.eager_load = ENV["CI"].present?
2321

24-
# Configure public file server for tests with Cache-Control for performance.
25-
config.public_file_server.enabled = true
26-
config.public_file_server.headers = {
27-
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
28-
}
22+
# Configure public file server for tests with cache-control for performance.
23+
config.public_file_server.headers =
24+
{ "cache-control" => "public, max-age=3600" }
2925

30-
# Show full error reports and disable caching.
31-
config.consider_all_requests_local = true
32-
config.action_controller.perform_caching = false
26+
# Show full error reports.
27+
config.consider_all_requests_local = true
3328
config.cache_store = :null_store
3429

35-
# Raise exceptions instead of rendering exception templates.
30+
# Render exception templates for rescuable exceptions and raise for other
31+
# exceptions.
3632
config.action_dispatch.show_exceptions = :rescuable
3733

3834
# Disable request forgery protection in test environment.
@@ -41,19 +37,13 @@
4137
# Print deprecation notices to the stderr.
4238
config.active_support.deprecation = :stderr
4339

44-
# Raise exceptions for disallowed deprecations.
45-
config.active_support.disallowed_deprecation = :raise
46-
47-
# Tell Active Support which deprecation messages to disallow.
48-
config.active_support.disallowed_deprecation_warnings = []
49-
5040
# Raises error for missing translations.
5141
# config.i18n.raise_on_missing_translations = true
5242

5343
# Annotate rendered view with file names.
5444
# config.action_view.annotate_rendered_view_with_filenames = true
5545

5646
# Raise error when a before_action's only/except options reference missing
57-
# actions
47+
# actions.
5848
config.action_controller.raise_on_missing_callback_actions = true
5949
end

config/initializers/assets.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,3 @@
77

88
# Add additional assets to the asset load path.
99
# Rails.application.config.assets.paths << Emoji.images_path
10-
11-
# Precompile additional assets.
12-
# application.js, application.css, and all non-JS/CSS in the app/assets
13-
# folder are already added.
14-
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

config/initializers/filter_parameter_logging.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,16 @@
77
# information. See the ActiveSupport::ParameterFilter documentation for
88
# supported notations and behaviors.
99
Rails.application.config.filter_parameters += [
10-
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
10+
:passw,
11+
:email,
12+
:secret,
13+
:token,
14+
:_key,
15+
:crypt,
16+
:salt,
17+
:certificate,
18+
:otp,
19+
:ssn,
20+
:cvv,
21+
:cvc
1122
]

0 commit comments

Comments
 (0)