Class: Trek::Generators::Install::ConfigGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/generators/trek/install/config_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_host_fileObject



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

#enable_forced_sslObject



12
13
14
# File 'lib/generators/trek/install/config_generator.rb', line 12

def enable_forced_ssl
  uncomment_lines("config/environments/production.rb", "config.force_ssl = true")
end