16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/generators/trek/install/config_generator.rb', line 16
def create_host_file
create_file "config/initializers/host.rb" do
<<~RUBY
# Default protocol, host and canonical_url
# Can be removed or refactored when this is merged:
# https://github.com/rails/rails/issues/39566
Rails.application.routes.default_url_options[:protocol] = Rails.application.config.force_ssl ? "https" : "http"
Rails.application.routes.default_url_options[:host] = ENV.fetch("DEFAULT_HOSTNAME", "localhost:3000")
Rails.application.config.canonical_url = "\#{Rails.application.routes.default_url_options[:protocol]}://\#{Rails.application.routes.default_url_options[:host]}"
# Mailers run outside a request, so in production they need the same host for
# link helpers. Development and test keep the host from their environment files.
# Deferred with on_load: referencing ActionMailer::Base here would load it
# before the app's autoloader can resolve app classes, and its load hook
# constantizes config.action_mailer.delivery_job — NameError at boot when
# the app configures a custom delivery job.
if Rails.env.production?
ActiveSupport.on_load(:action_mailer) do
self.default_url_options = Rails.application.routes.default_url_options
end
end
RUBY
end
end
|