<commit_before>**DO NOT READ THIS FILE ON GITHUB, GUIDES ARE PUBLISHED ON http://guides.rubyonrails.org.**

The Rails Initialization Process
================================

This guide explains the internals of the initialization process in Rails.
It is an extremely in-depth guide and recommended for advanced Rails developers.

After reading this guide, you will know:

* How to use `rails server`.
* The timeline of Rails' initialization sequence.
* Where different files are required by the boot sequence.
* How the Rails::Server interface is defined and used.

--------------------------------------------------------------------------------

This guide goes through every method call that is
required to boot up the Ruby on Rails stack for a default Rails
application, explaining each part in detail along the way. For this
guide, we will be focusing on what happens when you execute `rails server`
to boot your app.

NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified.

TIP: If you want to follow along while browsing the Rails [source
code](https://github.com/rails/rails), we recommend that you use the `t`
key binding to open the file finder inside GitHub and find files
quickly.

Launch!
-------

Let's start to boot and initialize the app. A Rails application is usually
started by running `rails console` or `rails server`.

### `railties/exe/rails`

The `rails` in the command `rails server` is a ruby executable in your load
path. This executable contains the following lines:

```ruby
version = ">= 0"
load Gem.bin_path('railties', 'rails', version)
```

If you try out this command in a Rails console, you would see that this loads
`railties/exe/rails`. A part of the file `railties/exe/rails.rb` has the
following code:

```ruby
require "rails/cli"
```

The file `railties/lib/rails/cli` in turn calls
`Rails::AppLoader.exec_app`.

### `railties/lib/rails/app_loader.rb`

The primary goal of the function `exec_app` is to execute your app's
`bin/rails`. If the current directory does not have a `bin/rails`, it will
navigate upwards until it finds a `bin/rails` executable. Thus one can invoke a
`rails` command from anywhere inside a rails application.

For `rails server` the equivalent of the following command is executed:

```bash
$ exec ruby bin/rails server
```

### `bin/rails`

This file is as follows:

```ruby
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)<commit_msg>fix error of a file name<commit_after>**DO NOT READ THIS FILE ON GITHUB, GUIDES ARE PUBLISHED ON http://guides.rubyonrails.org.**

The Rails Initialization Process
================================

This guide explains the internals of the initialization process in Rails.
It is an extremely in-depth guide and recommended for advanced Rails developers.

After reading this guide, you will know:

* How to use `rails server`.
* The timeline of Rails' initialization sequence.
* Where different files are required by the boot sequence.
* How the Rails::Server interface is defined and used.

--------------------------------------------------------------------------------

This guide goes through every method call that is
required to boot up the Ruby on Rails stack for a default Rails
application, explaining each part in detail along the way. For this
guide, we will be focusing on what happens when you execute `rails server`
to boot your app.

NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified.

TIP: If you want to follow along while browsing the Rails [source
code](https://github.com/rails/rails), we recommend that you use the `t`
key binding to open the file finder inside GitHub and find files
quickly.

Launch!
-------

Let's start to boot and initialize the app. A Rails application is usually
started by running `rails console` or `rails server`.

### `railties/exe/rails`

The `rails` in the command `rails server` is a ruby executable in your load
path. This executable contains the following lines:

```ruby
version = ">= 0"
load Gem.bin_path('railties', 'rails', version)
```

If you try out this command in a Rails console, you would see that this loads
`railties/exe/rails`. A part of the file `railties/exe/rails` has the
following code:

```ruby
require "rails/cli"
```

The file `railties/lib/rails/cli` in turn calls
`Rails::AppLoader.exec_app`.

### `railties/lib/rails/app_loader.rb`

The primary goal of the function `exec_app` is to execute your app's
`bin/rails`. If the current directory does not have a `bin/rails`, it will
navigate upwards until it finds a `bin/rails` executable. Thus one can invoke a
`rails` command from anywhere inside a rails application.

For `rails server` the equivalent of the following command is executed:

```bash
$ exec ruby bin/rails server
```

### `bin/rails`

This file is as follows:

```ruby
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.00040257648953301127, 'mean_word_length': 3.755023923444976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5978401', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1293, 'n_words': 674}