Class: RailsDynamicErrors::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rails_dynamic_errors/install_generator.rb

Overview

This is a generator that is used to install rails_dynamic_errors into a Rails application. It runs all of the methods below.

Instance Method Summary collapse

Instance Method Details

#configure_applicationObject

Add the gem configuration options to the Rails application’s config/application.rb file. These are all disabled by default so as to cause minimum intrusion upon install.



10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/rails_dynamic_errors/install_generator.rb', line 10

def configure_application
  application "# This option is used to set the HTTP error codes for which\n# rails_dynamic_errors will generate dynamic error pages. A good default\n# setup is [404, 422], which will catch the two main errors (excluding the\n# dreaded 500 Internal Server Error) for which Rails provides static HTML\n# error pages.\n# config.rails_dynamic_errors.http_error_status_codes_to_handle = [404, 422]\n  APP\nend\n"

#notify_about_routesObject

Add mounting of the gem’s engine to the the Rails application’s config/routes.rb file. The default mount path can be found in the documentation for the RailsDynamicErrors module.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/rails_dynamic_errors/install_generator.rb', line 24

def notify_about_routes
  insert_into_file File.join('config', 'routes.rb'), :before => /^end/ do
    %Q{
  # This line mounts RailDynamicErrors' routes on the '/errors' path of your
  # application. This means that any requests to URLs with this prefix in their
  # path will go to RailsDynamicErrors for processing.
  #
  # If you would like to change where this engine is mounted, simply change the
  # :at option to something different.
  mount RailsDynamicErrors::Engine, at: '#{RailsDynamicErrors::DEFAULT_MOUNT_PATH}'
    }
  end
end