Skip to content

Commit 6ef3a33

Browse files
authored
Resolve Rails 8 upgrade issues (#614)
* resolve Rails 8 upgrade issues
1 parent 8469bc7 commit 6ef3a33

12 files changed

+106
-321
lines changed

bin/dev

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
11
#!/usr/bin/env ruby
2-
exec "./bin/rails", "server", *ARGV
2+
# frozen_string_literal: true
3+
4+
def installed?(process)
5+
IO.popen "#{process} -v"
6+
rescue Errno::ENOENT
7+
false
8+
end
9+
10+
def run(process)
11+
system "#{process} start -f Procfile.dev"
12+
rescue Errno::ENOENT
13+
warn <<~MSG
14+
ERROR:
15+
Please ensure `Procfile.dev` exists in your project!
16+
MSG
17+
exit!
18+
end
19+
20+
if installed? "overmind"
21+
run "overmind"
22+
elsif installed? "foreman"
23+
run "foreman"
24+
else
25+
warn <<~MSG
26+
NOTICE:
27+
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
28+
MSG
29+
exit!
30+
end

bin/setup

+4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ FileUtils.chdir APP_ROOT do
1313
# Add necessary setup steps to this file.
1414

1515
puts "== Installing dependencies =="
16+
system! "gem install bundler --conservative"
1617
system("bundle check") || system!("bundle install")
1718

19+
# Install JavaScript dependencies
20+
system! "bin/yarn"
21+
1822
# puts "\n== Copying sample files =="
1923
# unless File.exist?("config/database.yml")
2024
# FileUtils.cp "config/database.yml.sample", "config/database.yml"

config/application.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Application < Rails::Application
2323
# These settings can be overridden in specific environments using the files
2424
# in config/environments, which are processed later.
2525

26-
config.active_support.to_time_preserves_timezone = :zone
26+
config.active_support.to_time_preserves_timezone = false
2727
# config.time_zone = "Central Time (US & Canada)"
2828
# config.eager_load_paths << Rails.root.join("extras")
2929
end

config/database.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ default: &default
3131

3232
development:
3333
<<: *default
34+
database: react-webpack-rails-tutoria-developmentl
3435

3536
# Warning: The database defined as "test" will be erased and
3637
# re-generated from your development database when you run "rake".
3738
# Do not set this db to the same as development or production.
3839
test:
3940
<<: *default
40-
database: react-webpack-rails-tutorial
41+
database: react-webpack-rails-tutorial-test
4142

4243
production:
4344
<<: *default

config/environments/development.rb

+12-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
if Rails.root.join("tmp/caching-dev.txt").exist?
2323
config.action_controller.perform_caching = true
2424
config.action_controller.enable_fragment_cache_logging = true
25+
config.cache_store = :memory_store
2526
config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" }
2627
else
28+
config.cache_store = :null_store
2729
config.action_controller.perform_caching = false
2830
end
2931

30-
# Change to :null_store to avoid any caching.
31-
config.cache_store = :memory_store
32-
3332
# Store uploaded files on the local file system (see config/storage.yml for options).
3433
config.active_storage.service = :local
3534

@@ -39,12 +38,15 @@
3938
# Make template changes take effect immediately.
4039
config.action_mailer.perform_caching = false
4140

42-
# Set localhost to be used by links generated in mailer templates.
43-
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
44-
4541
# Print deprecation notices to the Rails logger.
4642
config.active_support.deprecation = :log
4743

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+
4850
# Raise an error on page load if there are pending migrations.
4951
config.active_record.migration_error = :page_load
5052

@@ -63,6 +65,10 @@
6365
# Annotate rendered view with file names.
6466
config.action_view.annotate_rendered_view_with_filenames = true
6567

68+
# Use an evented file watcher to asynchronously detect changes in source code,
69+
# routes, locales, etc. This feature depends on the listen gem.
70+
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
71+
6672
# Uncomment if you wish to allow Action Cable access from any origin.
6773
# config.action_cable.disable_request_forgery_protection = true
6874

config/environments/production.rb

+46-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
# Turn on fragment caching in view templates.
1818
config.action_controller.perform_caching = true
1919

20+
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
21+
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
22+
# config.require_master_key = true
23+
24+
# Disable serving static files from the `/public` folder by default since
25+
# Apache or NGINX already handles this.
26+
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
27+
2028
# Cache assets for far-future expiry since they are all digest stamped.
2129
config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" }
2230

@@ -45,9 +53,6 @@
4553
# Prevent health checks from clogging up the logs.
4654
config.silence_healthcheck_path = "/up"
4755

48-
# Don't log any deprecations.
49-
config.active_support.report_deprecations = false
50-
5156
# Replace the default in-process memory cache store with a durable alternative.
5257
# config.cache_store = :mem_cache_store
5358

@@ -59,7 +64,7 @@
5964
# config.action_mailer.raise_delivery_errors = false
6065

6166
# Set host to be used by links generated in mailer templates.
62-
config.action_mailer.default_url_options = { host: "example.com" }
67+
# config.action_mailer.default_url_options = { host: "example.com" }
6368

6469
# Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit.
6570
# config.action_mailer.smtp_settings = {
@@ -74,11 +79,36 @@
7479
# the I18n.default_locale when a translation cannot be found).
7580
config.i18n.fallbacks = true
7681

82+
# Don't log any deprecations.
83+
# config.active_support.report_deprecations = false
84+
85+
# Send deprecation notices to registered listeners.
86+
config.active_support.deprecation = :notify
87+
88+
# Log disallowed deprecations.
89+
config.active_support.disallowed_deprecation = :log
90+
91+
# Tell Active Support which deprecation messages to disallow.
92+
config.active_support.disallowed_deprecation_warnings = []
93+
94+
# Use default logging formatter so that PID and timestamp are not suppressed.
95+
config.log_formatter = Logger::Formatter.new
96+
97+
# Use a different logger for distributed setups.
98+
# require "syslog/logger"
99+
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
100+
101+
if ENV["RAILS_LOG_TO_STDOUT"].present?
102+
logger = ActiveSupport::Logger.new($stdout)
103+
logger.formatter = config.log_formatter
104+
config.logger = ActiveSupport::TaggedLogging.new(logger)
105+
end
106+
77107
# Do not dump schema after migrations.
78108
config.active_record.dump_schema_after_migration = false
79109

80110
# Only use :id for inspections in production.
81-
config.active_record.attributes_for_inspect = [:id]
111+
# config.active_record.attributes_for_inspect = [:id]
82112

83113
# Enable DNS rebinding protection and other `Host` header attacks.
84114
# config.hosts = [
@@ -88,4 +118,15 @@
88118
#
89119
# Skip DNS rebinding protection for the default health check endpoint.
90120
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
121+
122+
# strategy for connection switching and pass that into the middleware through
123+
# these configuration options.
124+
# config.active_record.database_selector = { delay: 2.seconds }
125+
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
126+
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
127+
128+
# Action Cable endpoint configuration
129+
130+
config.action_cable.url = "wss://#{ENV.fetch('PRODUCTION_HOST', nil)}/cable"
131+
config.action_cable.allowed_request_origins = ["https://#{ENV.fetch('PRODUCTION_HOST', nil)}"]
91132
end

config/environments/test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
config.action_mailer.delivery_method = :test
4040

4141
# Set host to be used by links generated in mailer templates.
42-
config.action_mailer.default_url_options = { host: "example.com" }
42+
# config.action_mailer.default_url_options = { host: "example.com" }
4343

4444
# Print deprecation notices to the stderr.
4545
config.active_support.deprecation = :stderr

config/initializers/new_framework_defaults_6_1.rb

-64
This file was deleted.

0 commit comments

Comments
 (0)