rails 4.2.0.beta4 → 4.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/guides/Rakefile +3 -1
- data/guides/bug_report_templates/action_controller_gem.rb +2 -2
- data/guides/bug_report_templates/action_controller_master.rb +2 -2
- data/guides/source/3_0_release_notes.md +2 -2
- data/guides/source/4_1_release_notes.md +1 -1
- data/guides/source/4_2_release_notes.md +250 -225
- data/guides/source/_welcome.html.erb +1 -1
- data/guides/source/action_controller_overview.md +6 -6
- data/guides/source/action_mailer_basics.md +26 -11
- data/guides/source/action_view_overview.md +0 -1
- data/guides/source/active_job_basics.md +29 -23
- data/guides/source/active_record_postgresql.md +2 -7
- data/guides/source/active_record_validations.md +1 -0
- data/guides/source/active_support_core_extensions.md +1 -1
- data/guides/source/active_support_instrumentation.md +5 -5
- data/guides/source/asset_pipeline.md +2 -2
- data/guides/source/association_basics.md +0 -2
- data/guides/source/command_line.md +6 -15
- data/guides/source/configuring.md +4 -4
- data/guides/source/documents.yaml +0 -1
- data/guides/source/engines.md +26 -15
- data/guides/source/form_helpers.md +10 -2
- data/guides/source/getting_started.md +9 -9
- data/guides/source/rails_on_rack.md +2 -2
- data/guides/source/ruby_on_rails_guides_guidelines.md +1 -0
- data/guides/source/security.md +1 -1
- data/guides/source/testing.md +80 -13
- data/guides/source/upgrading_ruby_on_rails.md +23 -20
- metadata +29 -229
- data/guides/output/2_2_release_notes.html +0 -724
- data/guides/output/2_3_release_notes.html +0 -870
- data/guides/output/3_0_release_notes.html +0 -773
- data/guides/output/3_1_release_notes.html +0 -740
- data/guides/output/3_2_release_notes.html +0 -797
- data/guides/output/4_0_release_notes.html +0 -523
- data/guides/output/4_1_release_notes.html +0 -806
- data/guides/output/4_2_release_notes.html +0 -728
- data/guides/output/Gemfile +0 -6
- data/guides/output/_license.html +0 -226
- data/guides/output/_welcome.html +0 -233
- data/guides/output/action_controller_overview.html +0 -1335
- data/guides/output/action_mailer_basics.html +0 -928
- data/guides/output/action_view_overview.html +0 -1509
- data/guides/output/active_job_basics.html +0 -546
- data/guides/output/active_model_basics.html +0 -438
- data/guides/output/active_record_basics.html +0 -594
- data/guides/output/active_record_callbacks.html +0 -592
- data/guides/output/active_record_migrations.html +0 -1123
- data/guides/output/active_record_postgresql.html +0 -675
- data/guides/output/active_record_querying.html +0 -1796
- data/guides/output/active_record_validations.html +0 -1301
- data/guides/output/active_support_core_extensions.html +0 -3450
- data/guides/output/active_support_instrumentation.html +0 -1121
- data/guides/output/api_documentation_guidelines.html +0 -498
- data/guides/output/asset_pipeline.html +0 -1167
- data/guides/output/association_basics.html +0 -2086
- data/guides/output/caching_with_rails.html +0 -553
- data/guides/output/command_line.html +0 -791
- data/guides/output/configuring.html +0 -1055
- data/guides/output/contributing_to_ruby_on_rails.html +0 -657
- data/guides/output/credits.html +0 -284
- data/guides/output/debugging_rails_applications.html +0 -1014
- data/guides/output/development_dependencies_install.html +0 -478
- data/guides/output/engines.html +0 -1438
- data/guides/output/form_helpers.html +0 -1074
- data/guides/output/generators.html +0 -838
- data/guides/output/getting_started.html +0 -2092
- data/guides/output/i18n.html +0 -1198
- data/guides/output/images/akshaysurve.jpg +0 -0
- data/guides/output/images/belongs_to.png +0 -0
- data/guides/output/images/book_icon.gif +0 -0
- data/guides/output/images/bullet.gif +0 -0
- data/guides/output/images/chapters_icon.gif +0 -0
- data/guides/output/images/check_bullet.gif +0 -0
- data/guides/output/images/credits_pic_blank.gif +0 -0
- data/guides/output/images/csrf.png +0 -0
- data/guides/output/images/edge_badge.png +0 -0
- data/guides/output/images/favicon.ico +0 -0
- data/guides/output/images/feature_tile.gif +0 -0
- data/guides/output/images/footer_tile.gif +0 -0
- data/guides/output/images/fxn.png +0 -0
- data/guides/output/images/getting_started/article_with_comments.png +0 -0
- data/guides/output/images/getting_started/challenge.png +0 -0
- data/guides/output/images/getting_started/confirm_dialog.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
- data/guides/output/images/getting_started/form_with_errors.png +0 -0
- data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
- data/guides/output/images/getting_started/new_article.png +0 -0
- data/guides/output/images/getting_started/new_post.png +0 -0
- data/guides/output/images/getting_started/post_with_comments.png +0 -0
- data/guides/output/images/getting_started/rails_welcome.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
- data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
- data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
- data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
- data/guides/output/images/grey_bullet.gif +0 -0
- data/guides/output/images/habtm.png +0 -0
- data/guides/output/images/has_many.png +0 -0
- data/guides/output/images/has_many_through.png +0 -0
- data/guides/output/images/has_one.png +0 -0
- data/guides/output/images/has_one_through.png +0 -0
- data/guides/output/images/header_backdrop.png +0 -0
- data/guides/output/images/header_tile.gif +0 -0
- data/guides/output/images/i18n/demo_html_safe.png +0 -0
- data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translated_en.png +0 -0
- data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translation_missing.png +0 -0
- data/guides/output/images/i18n/demo_untranslated.png +0 -0
- data/guides/output/images/icons/README +0 -5
- data/guides/output/images/icons/callouts/1.png +0 -0
- data/guides/output/images/icons/callouts/10.png +0 -0
- data/guides/output/images/icons/callouts/11.png +0 -0
- data/guides/output/images/icons/callouts/12.png +0 -0
- data/guides/output/images/icons/callouts/13.png +0 -0
- data/guides/output/images/icons/callouts/14.png +0 -0
- data/guides/output/images/icons/callouts/15.png +0 -0
- data/guides/output/images/icons/callouts/2.png +0 -0
- data/guides/output/images/icons/callouts/3.png +0 -0
- data/guides/output/images/icons/callouts/4.png +0 -0
- data/guides/output/images/icons/callouts/5.png +0 -0
- data/guides/output/images/icons/callouts/6.png +0 -0
- data/guides/output/images/icons/callouts/7.png +0 -0
- data/guides/output/images/icons/callouts/8.png +0 -0
- data/guides/output/images/icons/callouts/9.png +0 -0
- data/guides/output/images/icons/caution.png +0 -0
- data/guides/output/images/icons/example.png +0 -0
- data/guides/output/images/icons/home.png +0 -0
- data/guides/output/images/icons/important.png +0 -0
- data/guides/output/images/icons/next.png +0 -0
- data/guides/output/images/icons/note.png +0 -0
- data/guides/output/images/icons/prev.png +0 -0
- data/guides/output/images/icons/tip.png +0 -0
- data/guides/output/images/icons/up.png +0 -0
- data/guides/output/images/icons/warning.png +0 -0
- data/guides/output/images/nav_arrow.gif +0 -0
- data/guides/output/images/oscardelben.jpg +0 -0
- data/guides/output/images/polymorphic.png +0 -0
- data/guides/output/images/radar.png +0 -0
- data/guides/output/images/rails4_features.png +0 -0
- data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
- data/guides/output/images/rails_guides_logo.gif +0 -0
- data/guides/output/images/rails_logo_remix.gif +0 -0
- data/guides/output/images/session_fixation.png +0 -0
- data/guides/output/images/tab_grey.gif +0 -0
- data/guides/output/images/tab_info.gif +0 -0
- data/guides/output/images/tab_note.gif +0 -0
- data/guides/output/images/tab_red.gif +0 -0
- data/guides/output/images/tab_yellow.gif +0 -0
- data/guides/output/images/tab_yellow.png +0 -0
- data/guides/output/images/vijaydev.jpg +0 -0
- data/guides/output/index.html +0 -354
- data/guides/output/initialization.html +0 -876
- data/guides/output/javascripts/guides.js +0 -59
- data/guides/output/javascripts/jquery.min.js +0 -4
- data/guides/output/javascripts/responsive-tables.js +0 -43
- data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
- data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
- data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
- data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
- data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
- data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
- data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
- data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
- data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
- data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
- data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
- data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
- data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
- data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
- data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
- data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
- data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
- data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
- data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
- data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
- data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
- data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
- data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
- data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
- data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
- data/guides/output/javascripts/syntaxhighlighter/shCore.js +0 -17
- data/guides/output/layout.html +0 -448
- data/guides/output/layouts_and_rendering.html +0 -1541
- data/guides/output/maintenance_policy.html +0 -257
- data/guides/output/migrations.html +0 -1360
- data/guides/output/nested_model_forms.html +0 -412
- data/guides/output/plugins.html +0 -644
- data/guides/output/rails_application_templates.html +0 -450
- data/guides/output/rails_on_rack.html +0 -547
- data/guides/output/routing.html +0 -1631
- data/guides/output/ruby_on_rails_guides_guidelines.html +0 -329
- data/guides/output/security.html +0 -935
- data/guides/output/stylesheets/fixes.css +0 -16
- data/guides/output/stylesheets/kindle.css +0 -11
- data/guides/output/stylesheets/main.css +0 -713
- data/guides/output/stylesheets/print.css +0 -52
- data/guides/output/stylesheets/reset.css +0 -43
- data/guides/output/stylesheets/responsive-tables.css +0 -50
- data/guides/output/stylesheets/style.css +0 -13
- data/guides/output/stylesheets/syntaxhighlighter/shCore.css +0 -226
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
- data/guides/output/testing.html +0 -1350
- data/guides/output/upgrading_ruby_on_rails.html +0 -1135
- data/guides/output/working_with_javascript_in_rails.html +0 -587
@@ -1,876 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
7
|
-
|
8
|
-
<title>The Rails Initialization Process — Ruby on Rails Guides</title>
|
9
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
10
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
11
|
-
|
12
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
13
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
|
16
|
-
|
17
|
-
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
|
18
|
-
</head>
|
19
|
-
<body class="guide">
|
20
|
-
<div id="topNav">
|
21
|
-
<div class="wrapper">
|
22
|
-
<strong class="more-info-label">More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
|
23
|
-
<span class="red-button more-info-button">
|
24
|
-
More Ruby on Rails
|
25
|
-
</span>
|
26
|
-
<ul class="more-info-links s-hidden">
|
27
|
-
<li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
|
28
|
-
<li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
|
29
|
-
<li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
|
30
|
-
<li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
|
31
|
-
<li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
|
32
|
-
<li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
|
33
|
-
<li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
|
34
|
-
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
|
35
|
-
</ul>
|
36
|
-
</div>
|
37
|
-
</div>
|
38
|
-
<div id="header">
|
39
|
-
<div class="wrapper clearfix">
|
40
|
-
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
|
41
|
-
<ul class="nav">
|
42
|
-
<li><a class="nav-item" href="index.html">Home</a></li>
|
43
|
-
<li class="guides-index guides-index-large">
|
44
|
-
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guides Index</a>
|
45
|
-
<div id="guides" class="clearfix" style="display: none;">
|
46
|
-
<hr />
|
47
|
-
<dl class="L">
|
48
|
-
<dt>Start Here</dt>
|
49
|
-
<dd><a href="getting_started.html">Getting Started with Rails</a></dd>
|
50
|
-
<dt>Models</dt>
|
51
|
-
<dd><a href="active_record_basics.html">Active Record Basics</a></dd>
|
52
|
-
<dd><a href="active_record_migrations.html">Active Record Migrations</a></dd>
|
53
|
-
<dd><a href="active_record_validations.html">Active Record Validations</a></dd>
|
54
|
-
<dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd>
|
55
|
-
<dd><a href="association_basics.html">Active Record Associations</a></dd>
|
56
|
-
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
|
57
|
-
<dt>Views</dt>
|
58
|
-
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
|
59
|
-
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
|
60
|
-
<dt>Controllers</dt>
|
61
|
-
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
|
62
|
-
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
|
63
|
-
</dl>
|
64
|
-
<dl class="R">
|
65
|
-
<dt>Digging Deeper</dt>
|
66
|
-
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
|
67
|
-
<dd><a href="i18n.html">Rails Internationalization API</a></dd>
|
68
|
-
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
|
69
|
-
<dd><a href="active_job_basics.html">Active Job Basics</a></dd>
|
70
|
-
<dd><a href="security.html">Securing Rails Applications</a></dd>
|
71
|
-
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
|
72
|
-
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
|
73
|
-
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
|
74
|
-
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
|
75
|
-
<dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd>
|
76
|
-
<dt>Extending Rails</dt>
|
77
|
-
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
|
78
|
-
<dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
|
79
|
-
<dt>Contributing to Ruby on Rails</dt>
|
80
|
-
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
|
81
|
-
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
82
|
-
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
83
|
-
<dt>Maintenance Policy</dt>
|
84
|
-
<dd><a href="maintenance_policy.html">Maintenance Policy</a></dd>
|
85
|
-
<dt>Release Notes</dt>
|
86
|
-
<dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd>
|
87
|
-
<dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</a></dd>
|
88
|
-
<dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</a></dd>
|
89
|
-
<dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</a></dd>
|
90
|
-
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
|
91
|
-
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
92
|
-
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
|
93
|
-
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
|
94
|
-
</dl>
|
95
|
-
</div>
|
96
|
-
</li>
|
97
|
-
<li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li>
|
98
|
-
<li><a class="nav-item" href="credits.html">Credits</a></li>
|
99
|
-
<li class="guides-index guides-index-small">
|
100
|
-
<select class="guides-index-item nav-item">
|
101
|
-
<option value="index.html">Guides Index</option>
|
102
|
-
<optgroup label="Start Here">
|
103
|
-
<option value="getting_started.html">Getting Started with Rails</option>
|
104
|
-
</optgroup>
|
105
|
-
<optgroup label="Models">
|
106
|
-
<option value="active_record_basics.html">Active Record Basics</option>
|
107
|
-
<option value="active_record_migrations.html">Active Record Migrations</option>
|
108
|
-
<option value="active_record_validations.html">Active Record Validations</option>
|
109
|
-
<option value="active_record_callbacks.html">Active Record Callbacks</option>
|
110
|
-
<option value="association_basics.html">Active Record Associations</option>
|
111
|
-
<option value="active_record_querying.html">Active Record Query Interface</option>
|
112
|
-
</optgroup>
|
113
|
-
<optgroup label="Views">
|
114
|
-
<option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option>
|
115
|
-
<option value="form_helpers.html">Action View Form Helpers</option>
|
116
|
-
</optgroup>
|
117
|
-
<optgroup label="Controllers">
|
118
|
-
<option value="action_controller_overview.html">Action Controller Overview</option>
|
119
|
-
<option value="routing.html">Rails Routing from the Outside In</option>
|
120
|
-
</optgroup>
|
121
|
-
<optgroup label="Digging Deeper">
|
122
|
-
<option value="active_support_core_extensions.html">Active Support Core Extensions</option>
|
123
|
-
<option value="i18n.html">Rails Internationalization API</option>
|
124
|
-
<option value="action_mailer_basics.html">Action Mailer Basics</option>
|
125
|
-
<option value="active_job_basics.html">Active Job Basics</option>
|
126
|
-
<option value="security.html">Securing Rails Applications</option>
|
127
|
-
<option value="debugging_rails_applications.html">Debugging Rails Applications</option>
|
128
|
-
<option value="configuring.html">Configuring Rails Applications</option>
|
129
|
-
<option value="command_line.html">Rails Command Line Tools and Rake Tasks</option>
|
130
|
-
<option value="asset_pipeline.html">Asset Pipeline</option>
|
131
|
-
<option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option>
|
132
|
-
</optgroup>
|
133
|
-
<optgroup label="Extending Rails">
|
134
|
-
<option value="rails_on_rack.html">Rails on Rack</option>
|
135
|
-
<option value="generators.html">Creating and Customizing Rails Generators</option>
|
136
|
-
</optgroup>
|
137
|
-
<optgroup label="Contributing to Ruby on Rails">
|
138
|
-
<option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option>
|
139
|
-
<option value="api_documentation_guidelines.html">API Documentation Guidelines</option>
|
140
|
-
<option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</option>
|
141
|
-
</optgroup>
|
142
|
-
<optgroup label="Maintenance Policy">
|
143
|
-
<option value="maintenance_policy.html">Maintenance Policy</option>
|
144
|
-
</optgroup>
|
145
|
-
<optgroup label="Release Notes">
|
146
|
-
<option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option>
|
147
|
-
<option value="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</option>
|
148
|
-
<option value="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</option>
|
149
|
-
<option value="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</option>
|
150
|
-
<option value="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</option>
|
151
|
-
<option value="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</option>
|
152
|
-
<option value="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</option>
|
153
|
-
<option value="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</option>
|
154
|
-
</optgroup>
|
155
|
-
</select>
|
156
|
-
</li>
|
157
|
-
</ul>
|
158
|
-
</div>
|
159
|
-
</div>
|
160
|
-
<hr class="hide" />
|
161
|
-
|
162
|
-
<div id="feature">
|
163
|
-
<div class="wrapper">
|
164
|
-
<h2>The Rails Initialization Process</h2><p>This guide explains the internals of the initialization process in Rails
|
165
|
-
as of Rails 4. It is an extremely in-depth guide and recommended for advanced Rails developers.</p><p>After reading this guide, you will know:</p>
|
166
|
-
<ul>
|
167
|
-
<li>How to use <code>rails server</code>.</li>
|
168
|
-
<li>The timeline of Rails' initialization sequence.</li>
|
169
|
-
<li>Where different files are required by the boot sequence.</li>
|
170
|
-
<li>How the Rails::Server interface is defined and used.</li>
|
171
|
-
</ul>
|
172
|
-
|
173
|
-
|
174
|
-
<div id="subCol">
|
175
|
-
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
|
176
|
-
<ol class="chapters">
|
177
|
-
<li>
|
178
|
-
<a href="#launch-bang">Launch!</a>
|
179
|
-
|
180
|
-
<ul>
|
181
|
-
<li><a href="#railties/bin/rails"><code>railties/bin/rails</code></a></li>
|
182
|
-
<li><a href="#railties/lib/rails/app_rails_loader.rb"><code>railties/lib/rails/app_rails_loader.rb</code></a></li>
|
183
|
-
<li><a href="#bin/rails"><code>bin/rails</code></a></li>
|
184
|
-
<li><a href="#config/boot.rb"><code>config/boot.rb</code></a></li>
|
185
|
-
<li><a href="#rails/commands.rb"><code>rails/commands.rb</code></a></li>
|
186
|
-
<li><a href="#rails/commands/command_tasks.rb"><code>rails/commands/command_tasks.rb</code></a></li>
|
187
|
-
<li><a href="#actionpack/lib/action_dispatch.rb"><code>actionpack/lib/action_dispatch.rb</code></a></li>
|
188
|
-
<li><a href="#rails/commands/server.rb"><code>rails/commands/server.rb</code></a></li>
|
189
|
-
<li><a href="#launch-bang-rack:-lib/rack/server.rb">Rack: <code>lib/rack/server.rb</code></a></li>
|
190
|
-
<li><a href="#config/application"><code>config/application</code></a></li>
|
191
|
-
<li><a href="#rails::server#start"><code>Rails::Server#start</code></a></li>
|
192
|
-
<li><a href="#config/environment.rb"><code>config/environment.rb</code></a></li>
|
193
|
-
<li><a href="#config/application.rb"><code>config/application.rb</code></a></li>
|
194
|
-
</ul>
|
195
|
-
</li>
|
196
|
-
<li>
|
197
|
-
<a href="#loading-rails">Loading Rails</a>
|
198
|
-
|
199
|
-
<ul>
|
200
|
-
<li><a href="#railties/lib/rails/all.rb"><code>railties/lib/rails/all.rb</code></a></li>
|
201
|
-
<li><a href="#back-to-config/environment.rb">Back to <code>config/environment.rb</code></a></li>
|
202
|
-
<li><a href="#railties/lib/rails/application.rb"><code>railties/lib/rails/application.rb</code></a></li>
|
203
|
-
<li><a href="#loading-rails-rack:-lib/rack/server.rb">Rack: lib/rack/server.rb</a></li>
|
204
|
-
</ul>
|
205
|
-
</li>
|
206
|
-
</ol>
|
207
|
-
|
208
|
-
</div>
|
209
|
-
|
210
|
-
</div>
|
211
|
-
</div>
|
212
|
-
|
213
|
-
<div id="container">
|
214
|
-
<div class="wrapper">
|
215
|
-
<div id="mainCol">
|
216
|
-
<p>This guide goes through every method call that is
|
217
|
-
required to boot up the Ruby on Rails stack for a default Rails 4
|
218
|
-
application, explaining each part in detail along the way. For this
|
219
|
-
guide, we will be focusing on what happens when you execute <code>rails server</code>
|
220
|
-
to boot your app.</p><div class="note"><p>Paths in this guide are relative to Rails or a Rails application unless otherwise specified.</p></div><div class="info"><p>If you want to follow along while browsing the Rails <a href="https://github.com/rails/rails">source
|
221
|
-
code</a>, we recommend that you use the <code>t</code>
|
222
|
-
key binding to open the file finder inside GitHub and find files
|
223
|
-
quickly.</p></div><h3 id="launch-bang">1 Launch!</h3><p>Let's start to boot and initialize the app. A Rails application is usually
|
224
|
-
started by running <code>rails console</code> or <code>rails server</code>.</p><h4 id="railties/bin/rails">1.1 <code>railties/bin/rails</code>
|
225
|
-
</h4><p>The <code>rails</code> in the command <code>rails server</code> is a ruby executable in your load
|
226
|
-
path. This executable contains the following lines:</p><div class="code_container">
|
227
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
228
|
-
version = ">= 0"
|
229
|
-
load Gem.bin_path('railties', 'rails', version)
|
230
|
-
|
231
|
-
</pre>
|
232
|
-
</div>
|
233
|
-
<p>If you try out this command in a Rails console, you would see that this loads
|
234
|
-
<code>railties/bin/rails</code>. A part of the file <code>railties/bin/rails.rb</code> has the
|
235
|
-
following code:</p><div class="code_container">
|
236
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
237
|
-
require "rails/cli"
|
238
|
-
|
239
|
-
</pre>
|
240
|
-
</div>
|
241
|
-
<p>The file <code>railties/lib/rails/cli</code> in turn calls
|
242
|
-
<code>Rails::AppRailsLoader.exec_app_rails</code>.</p><h4 id="railties/lib/rails/app_rails_loader.rb">1.2 <code>railties/lib/rails/app_rails_loader.rb</code>
|
243
|
-
</h4><p>The primary goal of the function <code>exec_app_rails</code> is to execute your app's
|
244
|
-
<code>bin/rails</code>. If the current directory does not have a <code>bin/rails</code>, it will
|
245
|
-
navigate upwards until it finds a <code>bin/rails</code> executable. Thus one can invoke a
|
246
|
-
<code>rails</code> command from anywhere inside a rails application.</p><p>For <code>rails server</code> the equivalent of the following command is executed:</p><div class="code_container">
|
247
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
248
|
-
$ exec ruby bin/rails server
|
249
|
-
|
250
|
-
</pre>
|
251
|
-
</div>
|
252
|
-
<h4 id="bin/rails">1.3 <code>bin/rails</code>
|
253
|
-
</h4><p>This file is as follows:</p><div class="code_container">
|
254
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
255
|
-
#!/usr/bin/env ruby
|
256
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
257
|
-
require_relative '../config/boot'
|
258
|
-
require 'rails/commands'
|
259
|
-
|
260
|
-
</pre>
|
261
|
-
</div>
|
262
|
-
<p>The <code>APP_PATH</code> constant will be used later in <code>rails/commands</code>. The <code>config/boot</code> file referenced here is the <code>config/boot.rb</code> file in our application which is responsible for loading Bundler and setting it up.</p><h4 id="config/boot.rb">1.4 <code>config/boot.rb</code>
|
263
|
-
</h4><p><code>config/boot.rb</code> contains:</p><div class="code_container">
|
264
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
265
|
-
# Set up gems listed in the Gemfile.
|
266
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
267
|
-
|
268
|
-
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
269
|
-
|
270
|
-
</pre>
|
271
|
-
</div>
|
272
|
-
<p>In a standard Rails application, there's a <code>Gemfile</code> which declares all
|
273
|
-
dependencies of the application. <code>config/boot.rb</code> sets
|
274
|
-
<code>ENV['BUNDLE_GEMFILE']</code> to the location of this file. If the Gemfile
|
275
|
-
exists, then <code>bundler/setup</code> is required. The require is used by Bundler to
|
276
|
-
configure the load path for your Gemfile's dependencies.</p><p>A standard Rails application depends on several gems, specifically:</p>
|
277
|
-
<ul>
|
278
|
-
<li>actionmailer</li>
|
279
|
-
<li>actionpack</li>
|
280
|
-
<li>actionview</li>
|
281
|
-
<li>activemodel</li>
|
282
|
-
<li>activerecord</li>
|
283
|
-
<li>activesupport</li>
|
284
|
-
<li>arel</li>
|
285
|
-
<li>builder</li>
|
286
|
-
<li>bundler</li>
|
287
|
-
<li>erubis</li>
|
288
|
-
<li>i18n</li>
|
289
|
-
<li>mail</li>
|
290
|
-
<li>mime-types</li>
|
291
|
-
<li>polyglot</li>
|
292
|
-
<li>rack</li>
|
293
|
-
<li>rack-cache</li>
|
294
|
-
<li>rack-mount</li>
|
295
|
-
<li>rack-test</li>
|
296
|
-
<li>rails</li>
|
297
|
-
<li>railties</li>
|
298
|
-
<li>rake</li>
|
299
|
-
<li>sqlite3</li>
|
300
|
-
<li>thor</li>
|
301
|
-
<li>treetop</li>
|
302
|
-
<li>tzinfo</li>
|
303
|
-
</ul>
|
304
|
-
<h4 id="rails/commands.rb">1.5 <code>rails/commands.rb</code>
|
305
|
-
</h4><p>Once <code>config/boot.rb</code> has finished, the next file that is required is
|
306
|
-
<code>rails/commands</code>, which helps in expanding aliases. In the current case, the
|
307
|
-
<code>ARGV</code> array simply contains <code>server</code> which will be passed over:</p><div class="code_container">
|
308
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
309
|
-
ARGV << '--help' if ARGV.empty?
|
310
|
-
|
311
|
-
aliases = {
|
312
|
-
"g" => "generate",
|
313
|
-
"d" => "destroy",
|
314
|
-
"c" => "console",
|
315
|
-
"s" => "server",
|
316
|
-
"db" => "dbconsole",
|
317
|
-
"r" => "runner"
|
318
|
-
}
|
319
|
-
|
320
|
-
command = ARGV.shift
|
321
|
-
command = aliases[command] || command
|
322
|
-
|
323
|
-
require 'rails/commands/commands_tasks'
|
324
|
-
|
325
|
-
Rails::CommandsTasks.new(ARGV).run_command!(command)
|
326
|
-
|
327
|
-
</pre>
|
328
|
-
</div>
|
329
|
-
<div class="info"><p>As you can see, an empty ARGV list will make Rails show the help
|
330
|
-
snippet.</p></div><p>If we had used <code>s</code> rather than <code>server</code>, Rails would have used the <code>aliases</code>
|
331
|
-
defined here to find the matching command.</p><h4 id="rails/commands/command_tasks.rb">1.6 <code>rails/commands/command_tasks.rb</code>
|
332
|
-
</h4><p>When one types an incorrect rails command, the <code>run_command</code> is responsible for
|
333
|
-
throwing an error message. If the command is valid, a method of the same name
|
334
|
-
is called.</p><div class="code_container">
|
335
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
336
|
-
COMMAND_WHITELIST = %(plugin generate destroy console server dbconsole application runner new version help)
|
337
|
-
|
338
|
-
def run_command!(command)
|
339
|
-
command = parse_command(command)
|
340
|
-
if COMMAND_WHITELIST.include?(command)
|
341
|
-
send(command)
|
342
|
-
else
|
343
|
-
write_error_message(command)
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
</pre>
|
348
|
-
</div>
|
349
|
-
<p>With the <code>server</code> command, Rails will further run the following code:</p><div class="code_container">
|
350
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
351
|
-
def set_application_directory!
|
352
|
-
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
|
353
|
-
end
|
354
|
-
|
355
|
-
def server
|
356
|
-
set_application_directory!
|
357
|
-
require_command!("server")
|
358
|
-
|
359
|
-
Rails::Server.new.tap do |server|
|
360
|
-
# We need to require application after the server sets environment,
|
361
|
-
# otherwise the --environment option given to the server won't propagate.
|
362
|
-
require APP_PATH
|
363
|
-
Dir.chdir(Rails.application.root)
|
364
|
-
server.start
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
def require_command!(command)
|
369
|
-
require "rails/commands/#{command}"
|
370
|
-
end
|
371
|
-
|
372
|
-
</pre>
|
373
|
-
</div>
|
374
|
-
<p>This file will change into the Rails root directory (a path two directories up
|
375
|
-
from <code>APP_PATH</code> which points at <code>config/application.rb</code>), but only if the
|
376
|
-
<code>config.ru</code> file isn't found. This then requires <code>rails/commands/server</code> which
|
377
|
-
sets up the <code>Rails::Server</code> class.</p><div class="code_container">
|
378
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
379
|
-
require 'fileutils'
|
380
|
-
require 'optparse'
|
381
|
-
require 'action_dispatch'
|
382
|
-
require 'rails'
|
383
|
-
|
384
|
-
module Rails
|
385
|
-
class Server < ::Rack::Server
|
386
|
-
|
387
|
-
</pre>
|
388
|
-
</div>
|
389
|
-
<p><code>fileutils</code> and <code>optparse</code> are standard Ruby libraries which provide helper functions for working with files and parsing options.</p><h4 id="actionpack/lib/action_dispatch.rb">1.7 <code>actionpack/lib/action_dispatch.rb</code>
|
390
|
-
</h4><p>Action Dispatch is the routing component of the Rails framework.
|
391
|
-
It adds functionality like routing, session, and common middlewares.</p><h4 id="rails/commands/server.rb">1.8 <code>rails/commands/server.rb</code>
|
392
|
-
</h4><p>The <code>Rails::Server</code> class is defined in this file by inheriting from <code>Rack::Server</code>. When <code>Rails::Server.new</code> is called, this calls the <code>initialize</code> method in <code>rails/commands/server.rb</code>:</p><div class="code_container">
|
393
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
394
|
-
def initialize(*)
|
395
|
-
super
|
396
|
-
set_environment
|
397
|
-
end
|
398
|
-
|
399
|
-
</pre>
|
400
|
-
</div>
|
401
|
-
<p>Firstly, <code>super</code> is called which calls the <code>initialize</code> method on <code>Rack::Server</code>.</p><h4 id="launch-bang-rack:-lib/rack/server.rb">1.9 Rack: <code>lib/rack/server.rb</code>
|
402
|
-
</h4><p><code>Rack::Server</code> is responsible for providing a common server interface for all Rack-based applications, which Rails is now a part of.</p><p>The <code>initialize</code> method in <code>Rack::Server</code> simply sets a couple of variables:</p><div class="code_container">
|
403
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
404
|
-
def initialize(options = nil)
|
405
|
-
@options = options
|
406
|
-
@app = options[:app] if options && options[:app]
|
407
|
-
end
|
408
|
-
|
409
|
-
</pre>
|
410
|
-
</div>
|
411
|
-
<p>In this case, <code>options</code> will be <code>nil</code> so nothing happens in this method.</p><p>After <code>super</code> has finished in <code>Rack::Server</code>, we jump back to <code>rails/commands/server.rb</code>. At this point, <code>set_environment</code> is called within the context of the <code>Rails::Server</code> object and this method doesn't appear to do much at first glance:</p><div class="code_container">
|
412
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
413
|
-
def set_environment
|
414
|
-
ENV["RAILS_ENV"] ||= options[:environment]
|
415
|
-
end
|
416
|
-
|
417
|
-
</pre>
|
418
|
-
</div>
|
419
|
-
<p>In fact, the <code>options</code> method here does quite a lot. This method is defined in <code>Rack::Server</code> like this:</p><div class="code_container">
|
420
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
421
|
-
def options
|
422
|
-
@options ||= parse_options(ARGV)
|
423
|
-
end
|
424
|
-
|
425
|
-
</pre>
|
426
|
-
</div>
|
427
|
-
<p>Then <code>parse_options</code> is defined like this:</p><div class="code_container">
|
428
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
429
|
-
def parse_options(args)
|
430
|
-
options = default_options
|
431
|
-
|
432
|
-
# Don't evaluate CGI ISINDEX parameters.
|
433
|
-
# http://www.meb.uni-bonn.de/docs/cgi/cl.html
|
434
|
-
args.clear if ENV.include?("REQUEST_METHOD")
|
435
|
-
|
436
|
-
options.merge! opt_parser.parse!(args)
|
437
|
-
options[:config] = ::File.expand_path(options[:config])
|
438
|
-
ENV["RACK_ENV"] = options[:environment]
|
439
|
-
options
|
440
|
-
end
|
441
|
-
|
442
|
-
</pre>
|
443
|
-
</div>
|
444
|
-
<p>With the <code>default_options</code> set to this:</p><div class="code_container">
|
445
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
446
|
-
def default_options
|
447
|
-
environment = ENV['RACK_ENV'] || 'development'
|
448
|
-
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
|
449
|
-
|
450
|
-
{
|
451
|
-
:environment => environment,
|
452
|
-
:pid => nil,
|
453
|
-
:Port => 9292,
|
454
|
-
:Host => default_host,
|
455
|
-
:AccessLog => [],
|
456
|
-
:config => "config.ru"
|
457
|
-
}
|
458
|
-
end
|
459
|
-
|
460
|
-
</pre>
|
461
|
-
</div>
|
462
|
-
<p>There is no <code>REQUEST_METHOD</code> key in <code>ENV</code> so we can skip over that line. The next line merges in the options from <code>opt_parser</code> which is defined plainly in <code>Rack::Server</code>:</p><div class="code_container">
|
463
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
464
|
-
def opt_parser
|
465
|
-
Options.new
|
466
|
-
end
|
467
|
-
|
468
|
-
</pre>
|
469
|
-
</div>
|
470
|
-
<p>The class <strong>is</strong> defined in <code>Rack::Server</code>, but is overwritten in <code>Rails::Server</code> to take different arguments. Its <code>parse!</code> method begins like this:</p><div class="code_container">
|
471
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
472
|
-
def parse!(args)
|
473
|
-
args, options = args.dup, {}
|
474
|
-
|
475
|
-
opt_parser = OptionParser.new do |opts|
|
476
|
-
opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
|
477
|
-
opts.on("-p", "--port=port", Integer,
|
478
|
-
"Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
|
479
|
-
...
|
480
|
-
|
481
|
-
</pre>
|
482
|
-
</div>
|
483
|
-
<p>This method will set up keys for the <code>options</code> which Rails will then be
|
484
|
-
able to use to determine how its server should run. After <code>initialize</code>
|
485
|
-
has finished, we jump back into <code>rails/server</code> where <code>APP_PATH</code> (which was
|
486
|
-
set earlier) is required.</p><h4 id="config/application">1.10 <code>config/application</code>
|
487
|
-
</h4><p>When <code>require APP_PATH</code> is executed, <code>config/application.rb</code> is loaded (recall
|
488
|
-
that <code>APP_PATH</code> is defined in <code>bin/rails</code>). This file exists in your application
|
489
|
-
and it's free for you to change based on your needs.</p><h4 id="rails::server#start">1.11 <code>Rails::Server#start</code>
|
490
|
-
</h4><p>After <code>config/application</code> is loaded, <code>server.start</code> is called. This method is
|
491
|
-
defined like this:</p><div class="code_container">
|
492
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
493
|
-
def start
|
494
|
-
print_boot_information
|
495
|
-
trap(:INT) { exit }
|
496
|
-
create_tmp_directories
|
497
|
-
log_to_stdout if options[:log_stdout]
|
498
|
-
|
499
|
-
super
|
500
|
-
...
|
501
|
-
end
|
502
|
-
|
503
|
-
private
|
504
|
-
|
505
|
-
def print_boot_information
|
506
|
-
...
|
507
|
-
puts "=> Run `rails server -h` for more startup options"
|
508
|
-
...
|
509
|
-
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
|
510
|
-
end
|
511
|
-
|
512
|
-
def create_tmp_directories
|
513
|
-
%w(cache pids sessions sockets).each do |dir_to_make|
|
514
|
-
FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make))
|
515
|
-
end
|
516
|
-
end
|
517
|
-
|
518
|
-
def log_to_stdout
|
519
|
-
wrapped_app # touch the app so the logger is set up
|
520
|
-
|
521
|
-
console = ActiveSupport::Logger.new($stdout)
|
522
|
-
console.formatter = Rails.logger.formatter
|
523
|
-
console.level = Rails.logger.level
|
524
|
-
|
525
|
-
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
526
|
-
end
|
527
|
-
|
528
|
-
</pre>
|
529
|
-
</div>
|
530
|
-
<p>This is where the first output of the Rails initialization happens. This
|
531
|
-
method creates a trap for <code>INT</code> signals, so if you <code>CTRL-C</code> the server,
|
532
|
-
it will exit the process. As we can see from the code here, it will
|
533
|
-
create the <code>tmp/cache</code>, <code>tmp/pids</code>, <code>tmp/sessions</code> and <code>tmp/sockets</code>
|
534
|
-
directories. It then calls <code>wrapped_app</code> which is responsible for
|
535
|
-
creating the Rack app, before creating and assigning an
|
536
|
-
instance of <code>ActiveSupport::Logger</code>.</p><p>The <code>super</code> method will call <code>Rack::Server.start</code> which begins its definition like this:</p><div class="code_container">
|
537
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
538
|
-
def start &blk
|
539
|
-
if options[:warn]
|
540
|
-
$-w = true
|
541
|
-
end
|
542
|
-
|
543
|
-
if includes = options[:include]
|
544
|
-
$LOAD_PATH.unshift(*includes)
|
545
|
-
end
|
546
|
-
|
547
|
-
if library = options[:require]
|
548
|
-
require library
|
549
|
-
end
|
550
|
-
|
551
|
-
if options[:debug]
|
552
|
-
$DEBUG = true
|
553
|
-
require 'pp'
|
554
|
-
p options[:server]
|
555
|
-
pp wrapped_app
|
556
|
-
pp app
|
557
|
-
end
|
558
|
-
|
559
|
-
check_pid! if options[:pid]
|
560
|
-
|
561
|
-
# Touch the wrapped app, so that the config.ru is loaded before
|
562
|
-
# daemonization (i.e. before chdir, etc).
|
563
|
-
wrapped_app
|
564
|
-
|
565
|
-
daemonize_app if options[:daemonize]
|
566
|
-
|
567
|
-
write_pid if options[:pid]
|
568
|
-
|
569
|
-
trap(:INT) do
|
570
|
-
if server.respond_to?(:shutdown)
|
571
|
-
server.shutdown
|
572
|
-
else
|
573
|
-
exit
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
577
|
-
server.run wrapped_app, options, &blk
|
578
|
-
end
|
579
|
-
|
580
|
-
</pre>
|
581
|
-
</div>
|
582
|
-
<p>The interesting part for a Rails app is the last line, <code>server.run</code>. Here we encounter the <code>wrapped_app</code> method again, which this time
|
583
|
-
we're going to explore more (even though it was executed before, and
|
584
|
-
thus memoized by now).</p><div class="code_container">
|
585
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
586
|
-
@wrapped_app ||= build_app app
|
587
|
-
|
588
|
-
</pre>
|
589
|
-
</div>
|
590
|
-
<p>The <code>app</code> method here is defined like so:</p><div class="code_container">
|
591
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
592
|
-
def app
|
593
|
-
@app ||= options[:builder] ? build_app_from_string : build_app_and_options_from_config
|
594
|
-
end
|
595
|
-
...
|
596
|
-
private
|
597
|
-
def build_app_and_options_from_config
|
598
|
-
if !::File.exist? options[:config]
|
599
|
-
abort "configuration #{options[:config]} not found"
|
600
|
-
end
|
601
|
-
|
602
|
-
app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
|
603
|
-
self.options.merge! options
|
604
|
-
app
|
605
|
-
end
|
606
|
-
|
607
|
-
def build_app_from_string
|
608
|
-
Rack::Builder.new_from_string(self.options[:builder])
|
609
|
-
end
|
610
|
-
|
611
|
-
</pre>
|
612
|
-
</div>
|
613
|
-
<p>The <code>options[:config]</code> value defaults to <code>config.ru</code> which contains this:</p><div class="code_container">
|
614
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
615
|
-
# This file is used by Rack-based servers to start the application.
|
616
|
-
|
617
|
-
require ::File.expand_path('../config/environment', __FILE__)
|
618
|
-
run <%= app_const %>
|
619
|
-
|
620
|
-
</pre>
|
621
|
-
</div>
|
622
|
-
<p>The <code>Rack::Builder.parse_file</code> method here takes the content from this <code>config.ru</code> file and parses it using this code:</p><div class="code_container">
|
623
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
624
|
-
app = new_from_string cfgfile, config
|
625
|
-
|
626
|
-
...
|
627
|
-
|
628
|
-
def self.new_from_string(builder_script, file="(rackup)")
|
629
|
-
eval "Rack::Builder.new {\n" + builder_script + "\n}.to_app",
|
630
|
-
TOPLEVEL_BINDING, file, 0
|
631
|
-
end
|
632
|
-
|
633
|
-
</pre>
|
634
|
-
</div>
|
635
|
-
<p>The <code>initialize</code> method of <code>Rack::Builder</code> will take the block here and execute it within an instance of <code>Rack::Builder</code>. This is where the majority of the initialization process of Rails happens. The <code>require</code> line for <code>config/environment.rb</code> in <code>config.ru</code> is the first to run:</p><div class="code_container">
|
636
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
637
|
-
require ::File.expand_path('../config/environment', __FILE__)
|
638
|
-
|
639
|
-
</pre>
|
640
|
-
</div>
|
641
|
-
<h4 id="config/environment.rb">1.12 <code>config/environment.rb</code>
|
642
|
-
</h4><p>This file is the common file required by <code>config.ru</code> (<code>rails server</code>) and Passenger. This is where these two ways to run the server meet; everything before this point has been Rack and Rails setup.</p><p>This file begins with requiring <code>config/application.rb</code>:</p><div class="code_container">
|
643
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
644
|
-
require File.expand_path('../application', __FILE__)
|
645
|
-
|
646
|
-
</pre>
|
647
|
-
</div>
|
648
|
-
<h4 id="config/application.rb">1.13 <code>config/application.rb</code>
|
649
|
-
</h4><p>This file requires <code>config/boot.rb</code>:</p><div class="code_container">
|
650
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
651
|
-
require File.expand_path('../boot', __FILE__)
|
652
|
-
|
653
|
-
</pre>
|
654
|
-
</div>
|
655
|
-
<p>But only if it hasn't been required before, which would be the case in <code>rails server</code>
|
656
|
-
but <strong>wouldn't</strong> be the case with Passenger.</p><p>Then the fun begins!</p><h3 id="loading-rails">2 Loading Rails</h3><p>The next line in <code>config/application.rb</code> is:</p><div class="code_container">
|
657
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
658
|
-
require 'rails/all'
|
659
|
-
|
660
|
-
</pre>
|
661
|
-
</div>
|
662
|
-
<h4 id="railties/lib/rails/all.rb">2.1 <code>railties/lib/rails/all.rb</code>
|
663
|
-
</h4><p>This file is responsible for requiring all the individual frameworks of Rails:</p><div class="code_container">
|
664
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
665
|
-
require "rails"
|
666
|
-
|
667
|
-
%w(
|
668
|
-
active_record
|
669
|
-
action_controller
|
670
|
-
action_view
|
671
|
-
action_mailer
|
672
|
-
rails/test_unit
|
673
|
-
sprockets
|
674
|
-
).each do |framework|
|
675
|
-
begin
|
676
|
-
require "#{framework}/railtie"
|
677
|
-
rescue LoadError
|
678
|
-
end
|
679
|
-
end
|
680
|
-
|
681
|
-
</pre>
|
682
|
-
</div>
|
683
|
-
<p>This is where all the Rails frameworks are loaded and thus made
|
684
|
-
available to the application. We won't go into detail of what happens
|
685
|
-
inside each of those frameworks, but you're encouraged to try and
|
686
|
-
explore them on your own.</p><p>For now, just keep in mind that common functionality like Rails engines,
|
687
|
-
I18n and Rails configuration are all being defined here.</p><h4 id="back-to-config/environment.rb">2.2 Back to <code>config/environment.rb</code>
|
688
|
-
</h4><p>The rest of <code>config/application.rb</code> defines the configuration for the
|
689
|
-
<code>Rails::Application</code> which will be used once the application is fully
|
690
|
-
initialized. When <code>config/application.rb</code> has finished loading Rails and defined
|
691
|
-
the application namespace, we go back to <code>config/environment.rb</code>,
|
692
|
-
where the application is initialized. For example, if the application was called
|
693
|
-
<code>Blog</code>, here we would find <code>Rails.application.initialize!</code>, which is
|
694
|
-
defined in <code>rails/application.rb</code>.</p><h4 id="railties/lib/rails/application.rb">2.3 <code>railties/lib/rails/application.rb</code>
|
695
|
-
</h4><p>The <code>initialize!</code> method looks like this:</p><div class="code_container">
|
696
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
697
|
-
def initialize!(group=:default) #:nodoc:
|
698
|
-
raise "Application has been already initialized." if @initialized
|
699
|
-
run_initializers(group, self)
|
700
|
-
@initialized = true
|
701
|
-
self
|
702
|
-
end
|
703
|
-
|
704
|
-
</pre>
|
705
|
-
</div>
|
706
|
-
<p>As you can see, you can only initialize an app once. The initializers are run through
|
707
|
-
the <code>run_initializers</code> method which is defined in <code>railties/lib/rails/initializable.rb</code>:</p><div class="code_container">
|
708
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
709
|
-
def run_initializers(group=:default, *args)
|
710
|
-
return if instance_variable_defined?(:@ran)
|
711
|
-
initializers.tsort_each do |initializer|
|
712
|
-
initializer.run(*args) if initializer.belongs_to?(group)
|
713
|
-
end
|
714
|
-
@ran = true
|
715
|
-
end
|
716
|
-
|
717
|
-
</pre>
|
718
|
-
</div>
|
719
|
-
<p>The <code>run_initializers</code> code itself is tricky. What Rails is doing here is
|
720
|
-
traversing all the class ancestors looking for those that respond to an
|
721
|
-
<code>initializers</code> method. It then sorts the ancestors by name, and runs them.
|
722
|
-
For example, the <code>Engine</code> class will make all the engines available by
|
723
|
-
providing an <code>initializers</code> method on them.</p><p>The <code>Rails::Application</code> class, as defined in <code>railties/lib/rails/application.rb</code>
|
724
|
-
defines <code>bootstrap</code>, <code>railtie</code>, and <code>finisher</code> initializers. The <code>bootstrap</code> initializers
|
725
|
-
prepare the application (like initializing the logger) while the <code>finisher</code>
|
726
|
-
initializers (like building the middleware stack) are run last. The <code>railtie</code>
|
727
|
-
initializers are the initializers which have been defined on the <code>Rails::Application</code>
|
728
|
-
itself and are run between the <code>bootstrap</code> and <code>finishers</code>.</p><p>After this is done we go back to <code>Rack::Server</code>.</p><h4 id="loading-rails-rack:-lib/rack/server.rb">2.4 Rack: lib/rack/server.rb</h4><p>Last time we left when the <code>app</code> method was being defined:</p><div class="code_container">
|
729
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
730
|
-
def app
|
731
|
-
@app ||= options[:builder] ? build_app_from_string : build_app_and_options_from_config
|
732
|
-
end
|
733
|
-
...
|
734
|
-
private
|
735
|
-
def build_app_and_options_from_config
|
736
|
-
if !::File.exist? options[:config]
|
737
|
-
abort "configuration #{options[:config]} not found"
|
738
|
-
end
|
739
|
-
|
740
|
-
app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
|
741
|
-
self.options.merge! options
|
742
|
-
app
|
743
|
-
end
|
744
|
-
|
745
|
-
def build_app_from_string
|
746
|
-
Rack::Builder.new_from_string(self.options[:builder])
|
747
|
-
end
|
748
|
-
|
749
|
-
</pre>
|
750
|
-
</div>
|
751
|
-
<p>At this point <code>app</code> is the Rails app itself (a middleware), and what
|
752
|
-
happens next is Rack will call all the provided middlewares:</p><div class="code_container">
|
753
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
754
|
-
def build_app(app)
|
755
|
-
middleware[options[:environment]].reverse_each do |middleware|
|
756
|
-
middleware = middleware.call(self) if middleware.respond_to?(:call)
|
757
|
-
next unless middleware
|
758
|
-
klass = middleware.shift
|
759
|
-
app = klass.new(app, *middleware)
|
760
|
-
end
|
761
|
-
app
|
762
|
-
end
|
763
|
-
|
764
|
-
</pre>
|
765
|
-
</div>
|
766
|
-
<p>Remember, <code>build_app</code> was called (by <code>wrapped_app</code>) in the last line of <code>Server#start</code>.
|
767
|
-
Here's how it looked like when we left:</p><div class="code_container">
|
768
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
769
|
-
server.run wrapped_app, options, &blk
|
770
|
-
|
771
|
-
</pre>
|
772
|
-
</div>
|
773
|
-
<p>At this point, the implementation of <code>server.run</code> will depend on the
|
774
|
-
server you're using. For example, if you were using Puma, here's what
|
775
|
-
the <code>run</code> method would look like:</p><div class="code_container">
|
776
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
777
|
-
...
|
778
|
-
DEFAULT_OPTIONS = {
|
779
|
-
:Host => '0.0.0.0',
|
780
|
-
:Port => 8080,
|
781
|
-
:Threads => '0:16',
|
782
|
-
:Verbose => false
|
783
|
-
}
|
784
|
-
|
785
|
-
def self.run(app, options = {})
|
786
|
-
options = DEFAULT_OPTIONS.merge(options)
|
787
|
-
|
788
|
-
if options[:Verbose]
|
789
|
-
app = Rack::CommonLogger.new(app, STDOUT)
|
790
|
-
end
|
791
|
-
|
792
|
-
if options[:environment]
|
793
|
-
ENV['RACK_ENV'] = options[:environment].to_s
|
794
|
-
end
|
795
|
-
|
796
|
-
server = ::Puma::Server.new(app)
|
797
|
-
min, max = options[:Threads].split(':', 2)
|
798
|
-
|
799
|
-
puts "Puma #{::Puma::Const::PUMA_VERSION} starting..."
|
800
|
-
puts "* Min threads: #{min}, max threads: #{max}"
|
801
|
-
puts "* Environment: #{ENV['RACK_ENV']}"
|
802
|
-
puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"
|
803
|
-
|
804
|
-
server.add_tcp_listener options[:Host], options[:Port]
|
805
|
-
server.min_threads = min
|
806
|
-
server.max_threads = max
|
807
|
-
yield server if block_given?
|
808
|
-
|
809
|
-
begin
|
810
|
-
server.run.join
|
811
|
-
rescue Interrupt
|
812
|
-
puts "* Gracefully stopping, waiting for requests to finish"
|
813
|
-
server.stop(true)
|
814
|
-
puts "* Goodbye!"
|
815
|
-
end
|
816
|
-
|
817
|
-
end
|
818
|
-
|
819
|
-
</pre>
|
820
|
-
</div>
|
821
|
-
<p>We won't dig into the server configuration itself, but this is
|
822
|
-
the last piece of our journey in the Rails initialization process.</p><p>This high level overview will help you understand when your code is
|
823
|
-
executed and how, and overall become a better Rails developer. If you
|
824
|
-
still want to know more, the Rails source code itself is probably the
|
825
|
-
best place to go next.</p>
|
826
|
-
|
827
|
-
<h3>Feedback</h3>
|
828
|
-
<p>
|
829
|
-
You're encouraged to help improve the quality of this guide.
|
830
|
-
</p>
|
831
|
-
<p>
|
832
|
-
Please contribute if you see any typos or factual errors.
|
833
|
-
To get started, you can read our <a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section.
|
834
|
-
</p>
|
835
|
-
<p>
|
836
|
-
You may also find incomplete content, or stuff that is not up to date.
|
837
|
-
Please do add any missing documentation for master. Make sure to check
|
838
|
-
<a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
|
839
|
-
if the issues are already fixed or not on the master branch.
|
840
|
-
Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
|
841
|
-
for style and conventions.
|
842
|
-
</p>
|
843
|
-
<p>
|
844
|
-
If for whatever reason you spot something to fix but cannot patch it yourself, please
|
845
|
-
<a href="https://github.com/rails/rails/issues">open an issue</a>.
|
846
|
-
</p>
|
847
|
-
<p>And last but not least, any kind of discussion regarding Ruby on Rails
|
848
|
-
documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
|
849
|
-
</p>
|
850
|
-
</div>
|
851
|
-
</div>
|
852
|
-
</div>
|
853
|
-
|
854
|
-
<hr class="hide" />
|
855
|
-
<div id="footer">
|
856
|
-
<div class="wrapper">
|
857
|
-
<p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p>
|
858
|
-
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
859
|
-
|
860
|
-
</div>
|
861
|
-
</div>
|
862
|
-
|
863
|
-
<script type="text/javascript" src="javascripts/jquery.min.js"></script>
|
864
|
-
<script type="text/javascript" src="javascripts/responsive-tables.js"></script>
|
865
|
-
<script type="text/javascript" src="javascripts/guides.js"></script>
|
866
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
867
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
868
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
869
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
870
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
871
|
-
<script type="text/javascript">
|
872
|
-
SyntaxHighlighter.all();
|
873
|
-
$(guidesIndex.bind);
|
874
|
-
</script>
|
875
|
-
</body>
|
876
|
-
</html>
|