Type:
Class
Constants:
INITIAL_VARIABLES : [:config, :railties, :routes_reloader, :reloaders, :routes, :helpers, :app_env_config, :secrets]

In Rails 3.0, a Rails::Application object was introduced which is nothing more than an Engine but with the responsibility of coordinating the whole boot process.

Initialization

Rails::Application is responsible for executing all railties and engines initializers. It also executes some bootstrap initializers (check Rails::Application::Bootstrap) and finishing initializers, after all the others are executed (check Rails::Application::Finisher).

Configuration

Besides providing the same configuration as Rails::Engine and Rails::Railtie, the application object has several specific configurations, for example “cache_classes”, “consider_all_requests_local”, “filter_parameters”, “logger” and so forth.

Check Rails::Application::Configuration to see them all.

Routes

The application object is also responsible for holding the routes and reloading routes whenever the files change in development.

Middlewares

The Application is also responsible for building the middleware stack.

Booting process

The application is also responsible for setting up and executing the booting process. From the moment you require “config/application.rb” in your app, the booting process goes like this:

1
2
3
4
5
6
7
8
9
10
11
12
1)  require "config/boot.rb" to setup load paths
2)  require railties and engines
3)  Define Rails.application as "class MyApp::Application < Rails::Application"
4)  Run config.before_configuration callbacks
5)  Load config/environments/ENV.rb
6)  Run config.before_initialize callbacks
7)  Run Railtie#initializer defined by railties, engines and application.
    One by one, each engine sets up its load paths, routes and runs its config/initializers/* files.
8)  Custom Railtie#initializers added by railties, engines and applications are executed
9)  Build the middleware stack and run to_prepare callbacks
10) Run config.before_eager_load and eager_load! if eager_load is true
11) Run config.after_initialize callbacks

Multiple Applications

If you decide to define multiple applications, then the first application that is initialized will be set to Rails.application, unless you override it with a different application.

To create a new application, you can instantiate a new instance of a class that has already been created:

1
2
3
4
5
class Application < Rails::Application
end
 
first_application  = Application.new
second_application = Application.new(config: first_application.config)

In the above example, the configuration from the first application was used to initialize the second application. You can also use the initialize_copy on one of the applications to create a copy of the application which shares the configuration.

If you decide to define rake tasks, runners, or initializers in an application other than Rails.application, then you must run those these manually.

message_verifier
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application

message_verifier(verifier_name) Instance Public methods Returns a message verifier

2025-01-10 15:47:30
build_stack
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application/Rails::Application::DefaultMiddlewareStack

build_stack() Instance Public methods

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application/Rails::Application::DefaultMiddlewareStack

new(app, config, paths) Class Public methods

2025-01-10 15:47:30
colorize_logging
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application/Rails::Application::Configuration

colorize_logging() Instance Public methods

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application/Rails::Application::Configuration

new(*) Class Public methods

2025-01-10 15:47:30
initializer
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application

initializer(name, opts={}, &block) Instance Public methods Sends the initializers

2025-01-10 15:47:30
secrets
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application

secrets() Instance Public methods Returns secrets added to config/secrets.yml

2025-01-10 15:47:30
env_config
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application

env_config() Instance Public methods Stores some of the Rails initial environment

2025-01-10 15:47:30
paths
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application/Rails::Application::Configuration

paths() Instance Public methods

2025-01-10 15:47:30
reload_routes!
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Application

reload_routes!() Instance Public methods Reload application routes regardless

2025-01-10 15:47:30