railties 3.1.1 → 3.1.2.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/CHANGELOG.md +2382 -0
  2. data/guides/output/2_2_release_notes.html +565 -0
  3. data/guides/output/2_3_release_notes.html +713 -0
  4. data/guides/output/3_0_release_notes.html +652 -0
  5. data/guides/output/3_1_release_notes.html +670 -0
  6. data/guides/output/action_controller_overview.html +925 -0
  7. data/guides/output/action_mailer_basics.html +658 -0
  8. data/guides/output/action_view_overview.html +1471 -0
  9. data/guides/output/active_model_basics.html +349 -0
  10. data/guides/output/active_record_basics.html +364 -0
  11. data/guides/output/active_record_querying.html +1272 -0
  12. data/guides/output/active_record_validations_callbacks.html +1292 -0
  13. data/guides/output/active_resource_basics.html +252 -0
  14. data/guides/output/active_support_core_extensions.html +3374 -0
  15. data/guides/output/ajax_on_rails.html +412 -0
  16. data/guides/output/api_documentation_guidelines.html +317 -0
  17. data/guides/output/asset_pipeline.html +691 -0
  18. data/guides/output/association_basics.html +1742 -0
  19. data/guides/output/caching_with_rails.html +533 -0
  20. data/guides/output/command_line.html +662 -0
  21. data/guides/output/configuring.html +811 -0
  22. data/guides/output/contribute.html +216 -0
  23. data/guides/output/contributing_to_ruby_on_rails.html +465 -0
  24. data/guides/output/credits.html +210 -0
  25. data/guides/output/debugging_rails_applications.html +791 -0
  26. data/guides/output/engines.html +673 -0
  27. data/guides/output/form_helpers.html +850 -0
  28. data/guides/output/generators.html +725 -0
  29. data/guides/output/getting_started.html +1980 -0
  30. data/guides/output/i18n.html +1054 -0
  31. data/guides/output/images/belongs_to.png +0 -0
  32. data/guides/output/images/book_icon.gif +0 -0
  33. data/guides/output/images/bullet.gif +0 -0
  34. data/guides/output/images/challenge.png +0 -0
  35. data/guides/output/images/chapters_icon.gif +0 -0
  36. data/guides/output/images/check_bullet.gif +0 -0
  37. data/guides/output/images/credits_pic_blank.gif +0 -0
  38. data/guides/output/images/csrf.png +0 -0
  39. data/guides/output/images/customized_error_messages.png +0 -0
  40. data/guides/output/images/edge_badge.png +0 -0
  41. data/guides/output/images/error_messages.png +0 -0
  42. data/guides/output/images/feature_tile.gif +0 -0
  43. data/guides/output/images/footer_tile.gif +0 -0
  44. data/guides/output/images/fxn.png +0 -0
  45. data/guides/output/images/grey_bullet.gif +0 -0
  46. data/guides/output/images/habtm.png +0 -0
  47. data/guides/output/images/has_many.png +0 -0
  48. data/guides/output/images/has_many_through.png +0 -0
  49. data/guides/output/images/has_one.png +0 -0
  50. data/guides/output/images/has_one_through.png +0 -0
  51. data/guides/output/images/header_backdrop.png +0 -0
  52. data/guides/output/images/header_tile.gif +0 -0
  53. data/guides/output/images/i18n/demo_html_safe.png +0 -0
  54. data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
  55. data/guides/output/images/i18n/demo_translated_en.png +0 -0
  56. data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
  57. data/guides/output/images/i18n/demo_translation_missing.png +0 -0
  58. data/guides/output/images/i18n/demo_untranslated.png +0 -0
  59. data/guides/output/images/icons/README +5 -0
  60. data/guides/output/images/icons/callouts/1.png +0 -0
  61. data/guides/output/images/icons/callouts/10.png +0 -0
  62. data/guides/output/images/icons/callouts/11.png +0 -0
  63. data/guides/output/images/icons/callouts/12.png +0 -0
  64. data/guides/output/images/icons/callouts/13.png +0 -0
  65. data/guides/output/images/icons/callouts/14.png +0 -0
  66. data/guides/output/images/icons/callouts/15.png +0 -0
  67. data/guides/output/images/icons/callouts/2.png +0 -0
  68. data/guides/output/images/icons/callouts/3.png +0 -0
  69. data/guides/output/images/icons/callouts/4.png +0 -0
  70. data/guides/output/images/icons/callouts/5.png +0 -0
  71. data/guides/output/images/icons/callouts/6.png +0 -0
  72. data/guides/output/images/icons/callouts/7.png +0 -0
  73. data/guides/output/images/icons/callouts/8.png +0 -0
  74. data/guides/output/images/icons/callouts/9.png +0 -0
  75. data/guides/output/images/icons/caution.png +0 -0
  76. data/guides/output/images/icons/example.png +0 -0
  77. data/guides/output/images/icons/home.png +0 -0
  78. data/guides/output/images/icons/important.png +0 -0
  79. data/guides/output/images/icons/next.png +0 -0
  80. data/guides/output/images/icons/note.png +0 -0
  81. data/guides/output/images/icons/prev.png +0 -0
  82. data/guides/output/images/icons/tip.png +0 -0
  83. data/guides/output/images/icons/up.png +0 -0
  84. data/guides/output/images/icons/warning.png +0 -0
  85. data/guides/output/images/jaimeiniesta.jpg +0 -0
  86. data/guides/output/images/nav_arrow.gif +0 -0
  87. data/guides/output/images/polymorphic.png +0 -0
  88. data/guides/output/images/posts_index.png +0 -0
  89. data/guides/output/images/radar.png +0 -0
  90. data/guides/output/images/rails_guides_logo.gif +0 -0
  91. data/guides/output/images/rails_logo_remix.gif +0 -0
  92. data/guides/output/images/rails_welcome.png +0 -0
  93. data/guides/output/images/session_fixation.png +0 -0
  94. data/guides/output/images/tab_grey.gif +0 -0
  95. data/guides/output/images/tab_info.gif +0 -0
  96. data/guides/output/images/tab_note.gif +0 -0
  97. data/guides/output/images/tab_red.gif +0 -0
  98. data/guides/output/images/tab_yellow.gif +0 -0
  99. data/guides/output/images/tab_yellow.png +0 -0
  100. data/guides/output/images/validation_error_messages.png +0 -0
  101. data/guides/output/images/vijaydev.jpg +0 -0
  102. data/guides/output/index.html +300 -0
  103. data/guides/output/initialization.html +1087 -0
  104. data/guides/output/javascripts/guides.js +7 -0
  105. data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
  106. data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
  107. data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
  108. data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
  109. data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
  110. data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
  111. data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
  112. data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
  113. data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
  114. data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
  115. data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
  116. data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
  117. data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
  118. data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
  119. data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
  120. data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
  121. data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
  122. data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
  123. data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
  124. data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
  125. data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
  126. data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
  127. data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
  128. data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
  129. data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
  130. data/guides/output/javascripts/syntaxhighlighter/shCore.js +17 -0
  131. data/guides/output/layout.html +312 -0
  132. data/guides/output/layouts_and_rendering.html +1257 -0
  133. data/guides/output/migrations.html +751 -0
  134. data/guides/output/nested_model_forms.html +350 -0
  135. data/guides/output/performance_testing.html +858 -0
  136. data/guides/output/plugins.html +590 -0
  137. data/guides/output/rails_application_templates.html +368 -0
  138. data/guides/output/rails_on_rack.html +408 -0
  139. data/guides/output/routing.html +1246 -0
  140. data/guides/output/ruby_on_rails_guides_guidelines.html +218 -0
  141. data/guides/output/security.html +968 -0
  142. data/guides/output/stylesheets/fixes.css +16 -0
  143. data/guides/output/stylesheets/main.css +445 -0
  144. data/guides/output/stylesheets/print.css +52 -0
  145. data/guides/output/stylesheets/reset.css +43 -0
  146. data/guides/output/stylesheets/style.css +13 -0
  147. data/guides/output/stylesheets/syntaxhighlighter/shCore.css +226 -0
  148. data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
  149. data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
  150. data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
  151. data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
  152. data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  153. data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
  154. data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
  155. data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
  156. data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
  157. data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
  158. data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
  159. data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
  160. data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  161. data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
  162. data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
  163. data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
  164. data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
  165. data/guides/output/testing.html +1182 -0
  166. data/guides/source/active_record_validations_callbacks.textile +3 -3
  167. data/guides/source/active_support_core_extensions.textile +2 -2
  168. data/guides/source/asset_pipeline.textile +7 -5
  169. data/guides/source/association_basics.textile +2 -4
  170. data/guides/source/command_line.textile +1 -1
  171. data/guides/source/configuring.textile +4 -2
  172. data/guides/source/contributing_to_ruby_on_rails.textile +6 -6
  173. data/guides/source/initialization.textile +2 -2
  174. data/guides/source/performance_testing.textile +1 -1
  175. data/guides/source/routing.textile +1 -1
  176. data/guides/source/security.textile +2 -2
  177. data/lib/rails/commands/server.rb +1 -1
  178. data/lib/rails/engine.rb +1 -1
  179. data/lib/rails/generators/app_base.rb +2 -1
  180. data/lib/rails/generators/base.rb +3 -3
  181. data/lib/rails/generators/rails/app/templates/gitignore +15 -5
  182. data/lib/rails/rack.rb +0 -1
  183. data/lib/rails/tasks/documentation.rake +7 -7
  184. data/lib/rails/tasks/misc.rake +0 -2
  185. data/lib/rails/test_unit/testing.rake +2 -0
  186. data/lib/rails/version.rb +2 -2
  187. metadata +495 -326
  188. data/CHANGELOG +0 -2371
  189. data/lib/rails/rack/content_length.rb +0 -38
@@ -0,0 +1,811 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+
8
+ <title>Ruby on Rails Guides: Configuring Rails Applications</title>
9
+
10
+ <link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
11
+ <link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
12
+
13
+ <link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
14
+ <link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
15
+
16
+ <link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
17
+ </head>
18
+ <body class="guide">
19
+ <div id="topNav">
20
+ <div class="wrapper">
21
+ <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
22
+ <a href="http://rubyonrails.org/">Overview</a> |
23
+ <a href="http://rubyonrails.org/download">Download</a> |
24
+ <a href="http://rubyonrails.org/deploy">Deploy</a> |
25
+ <a href="https://github.com/rails/rails">Code</a> |
26
+ <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
27
+ <a href="http://rubyonrails.org/documentation">Documentation</a> |
28
+ <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
29
+ <a href="http://rubyonrails.org/community">Community</a> |
30
+ <a href="http://weblog.rubyonrails.org/">Blog</a>
31
+ </div>
32
+ </div>
33
+ <div id="header">
34
+ <div class="wrapper clearfix">
35
+ <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
36
+ <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
37
+ <ul class="nav">
38
+ <li><a href="index.html">Home</a></li>
39
+ <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
40
+ <div id="guides" class="clearfix" style="display: none;">
41
+ <hr />
42
+ <dl class="L">
43
+ <dt>Start Here</dt>
44
+ <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
45
+ <dt>Models</dt>
46
+ <dd><a href="migrations.html">Rails Database Migrations</a></dd>
47
+ <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
48
+ <dd><a href="association_basics.html">Active Record Associations</a></dd>
49
+ <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
50
+ <dt>Views</dt>
51
+ <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
52
+ <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
53
+ <dt>Controllers</dt>
54
+ <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
55
+ <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
56
+ </dl>
57
+ <dl class="R">
58
+ <dt>Digging Deeper</dt>
59
+ <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
60
+ <dd><a href="i18n.html">Rails Internationalization API</a></dd>
61
+ <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
62
+ <dd><a href="testing.html">Testing Rails Applications</a></dd>
63
+ <dd><a href="security.html">Securing Rails Applications</a></dd>
64
+ <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
65
+ <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
66
+ <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
67
+ <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
68
+ <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
69
+ <dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
70
+
71
+ <dt>Extending Rails</dt>
72
+ <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
73
+ <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
74
+ <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
75
+
76
+ <dt>Contributing to Ruby on Rails</dt>
77
+ <dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
78
+ <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
79
+ <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
80
+
81
+ <dt>Release Notes</dt>
82
+ <dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
83
+ <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
84
+ <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
85
+ <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
86
+ </dl>
87
+ </div>
88
+ </li>
89
+ <li><a href="contributing_to_ruby_on_rails.html">Contribute</a></li>
90
+ <li><a href="credits.html">Credits</a></li>
91
+ </ul>
92
+ </div>
93
+ </div>
94
+ <hr class="hide" />
95
+
96
+ <div id="feature">
97
+ <div class="wrapper">
98
+ <h2>Configuring Rails Applications</h2>
99
+ <p>This guide covers the configuration and initialization features available to Rails applications. By referring to this guide, you will be able to:</p>
100
+ <ul>
101
+ <li>Adjust the behavior of your Rails applications</li>
102
+ <li>Add additional code to be run at application start time</li>
103
+ </ul>
104
+
105
+ <div id="subCol">
106
+ <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
107
+ <ol class="chapters">
108
+ <li><a href="#locations-for-initialization-code">Locations for Initialization Code</a></li><li><a href="#running-code-before-rails">Running Code Before Rails</a></li><li><a href="#configuring-rails-components">Configuring Rails Components</a><ul><li><a href="#rails-general-configuration">Rails General Configuration</a></li> <li><a href="#configuring-assets">Configuring Assets</a></li> <li><a href="#configuring-generators">Configuring Generators</a></li> <li><a href="#configuring-middleware">Configuring Middleware</a></li> <li><a href="#configuring-i18n">Configuring i18n</a></li> <li><a href="#configuring-active-record">Configuring Active Record</a></li> <li><a href="#configuring-action-controller">Configuring Action Controller</a></li> <li><a href="#configuring-action-dispatch">Configuring Action Dispatch</a></li> <li><a href="#configuring-action-view">Configuring Action View</a></li> <li><a href="#configuring-action-mailer">Configuring Action Mailer</a></li> <li><a href="#configuring-active-resource">Configuring Active Resource</a></li> <li><a href="#configuring-active-support">Configuring Active Support</a></li></ul></li><li><a href="#rails-environment-settings">Rails Environment Settings</a></li><li><a href="#using-initializer-files">Using Initializer Files</a></li><li><a href="#initialization-events">Initialization events</a><ul><li><a href="#rails-railtie-initializer"><tt>Rails::Railtie#initializer</tt></a></li> <li><a href="#initializers">Initializers</a></li></ul></li></ol></div>
109
+ </div>
110
+ </div>
111
+
112
+ <div id="container">
113
+ <div class="wrapper">
114
+ <div id="mainCol">
115
+ <h3 id="locations-for-initialization-code">1 Locations for Initialization Code</h3>
116
+ <p>Rails offers four standard spots to place initialization code:</p>
117
+ <ul>
118
+ <li><tt>config/application.rb</tt></li>
119
+ <li>Environment-specific configuration files</li>
120
+ <li>Initializers</li>
121
+ <li>After-initializers</li>
122
+ </ul>
123
+ <h3 id="running-code-before-rails">2 Running Code Before Rails</h3>
124
+ <p>In the rare event that your application needs to run some code before Rails itself is loaded, put it above the call to <tt>require 'rails/all'</tt> in <tt>config/application.rb</tt>.</p>
125
+ <h3 id="configuring-rails-components">3 Configuring Rails Components</h3>
126
+ <p>In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file <tt>config/application.rb</tt> and environment-specific configuration files (such as <tt>config/environments/production.rb</tt>) allow you to specify the various settings that you want to pass down to all of the components.</p>
127
+ <p>For example, the default <tt>config/application.rb</tt> file includes this setting:</p>
128
+ <div class="code_container">
129
+ <pre class="brush: ruby; gutter: false; toolbar: false">
130
+ config.filter_parameters += [:password]
131
+ </pre>
132
+ </div>
133
+ <p>This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same <tt>config</tt> object in <tt>config/application.rb</tt>:</p>
134
+ <div class="code_container">
135
+ <pre class="brush: ruby; gutter: false; toolbar: false">
136
+ config.active_record.observers = [:hotel_observer, :review_observer]
137
+ </pre>
138
+ </div>
139
+ <p>Rails will use that particular setting to configure Active Record.</p>
140
+ <h4 id="rails-general-configuration">3.1 Rails General Configuration</h4>
141
+ <ul>
142
+ <li><tt>config.after_initialize</tt> takes a block which will be run <em>after</em> Rails has finished initializing the application. That includes the initialization of the framework itself, plugins, engines, and all the application&#8217;s initializers in <tt>config/initializers</tt>. Note that this block <em>will</em> be run for rake tasks. Useful for configuring values set up by other initializers:</li>
143
+ </ul>
144
+ <div class="code_container">
145
+ <pre class="brush: ruby; gutter: false; toolbar: false">
146
+ config.after_initialize do
147
+ ActionView::Base.sanitized_allowed_tags.delete 'div'
148
+ end
149
+ </pre>
150
+ </div>
151
+ <ul>
152
+ <li><tt>config.allow_concurrency</tt> should be true to allow concurrent (threadsafe) action processing. False by default. You probably don&#8217;t want to call this one directly, though, because a series of other adjustments need to be made for threadsafe mode to work properly. Can also be enabled with <tt>threadsafe!</tt>.</li>
153
+ </ul>
154
+ <ul>
155
+ <li><tt>config.asset_host</tt> sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints builtin in browsers using different domain aliases. Shorter version of <tt>config.action_controller.asset_host</tt>.</li>
156
+ </ul>
157
+ <ul>
158
+ <li><tt>config.asset_path</tt> lets you decorate asset paths. This can be a callable, a string, or be <tt>nil</tt> which is the default. For example, the normal path for <tt>blog.js</tt> would be <tt>/javascripts/blog.js</tt>, let that absolute path be <tt>path</tt>. If <tt>config.asset_path</tt> is a callable, Rails calls it when generating asset paths passing <tt>path</tt> as argument. If <tt>config.asset_path</tt> is a string, it is expected to be a <tt>sprintf</tt> format string with a <tt>%s</tt> where <tt>path</tt> will get inserted. In either case, Rails outputs the decorated path. Shorter version of <tt>config.action_controller.asset_path</tt>.</li>
159
+ </ul>
160
+ <div class="code_container">
161
+ <pre class="brush: ruby; gutter: false; toolbar: false">
162
+ config.asset_path = proc { |path| &quot;/blog/public#{path}&quot; }
163
+ </pre>
164
+ </div>
165
+ <div class="note"><p>The <tt>config.asset_path</tt> configuration is ignored if the asset pipeline is enabled, which is the default.</p></div>
166
+ <ul>
167
+ <li><tt>config.autoload_once_paths</tt> accepts an array of paths from which Rails will autoload constants that won&#8217;t be wiped per request. Relevant if <tt>config.cache_classes</tt> is false, which is the case in development mode by default. Otherwise, all autoloading happens only once. All elements of this array must also be in <tt>autoload_paths</tt>. Default is an empty array.</li>
168
+ </ul>
169
+ <ul>
170
+ <li><tt>config.autoload_paths</tt> accepts an array of paths from which Rails will autoload constants. Default is all directories under <tt>app</tt>.</li>
171
+ </ul>
172
+ <ul>
173
+ <li><tt>config.cache_classes</tt> controls whether or not application classes and modules should be reloaded on each request. Defaults to false in development mode, and true in test and production modes. Can also be enabled with <tt>threadsafe!</tt>.</li>
174
+ </ul>
175
+ <ul>
176
+ <li><tt>config.action_view.cache_template_loading</tt> controls whether or not templates should be reloaded on each request. Defaults to whatever is set for <tt>config.cache_classes</tt>.</li>
177
+ </ul>
178
+ <ul>
179
+ <li><tt>config.cache_store</tt> configures which cache store to use for Rails caching. Options include one of the symbols <tt>:memory_store</tt>, <tt>:file_store</tt>, <tt>:mem_cache_store</tt>, or an object that implements the cache <span class="caps">API</span>. Defaults to <tt>:file_store</tt> if the directory <tt>tmp/cache</tt> exists, and to <tt>:memory_store</tt> otherwise.</li>
180
+ </ul>
181
+ <ul>
182
+ <li><tt>config.colorize_logging</tt> specifies whether or not to use <span class="caps">ANSI</span> color codes when logging information. Defaults to true.</li>
183
+ </ul>
184
+ <ul>
185
+ <li><tt>config.consider_all_requests_local</tt> is a flag. If true then any error will cause detailed debugging information to be dumped in the <span class="caps">HTTP</span> response, and the <tt>Rails::Info</tt> controller will show the application runtime context in <tt>/rails/info/properties</tt>. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement <tt>local_request?</tt> in controllers to specify which requests should provide debugging information on errors.</li>
186
+ </ul>
187
+ <ul>
188
+ <li><tt>config.dependency_loading</tt> is a flag that allows you to disable constant autoloading setting it to false. It only has effect if <tt>config.cache_classes</tt> is true, which it is by default in production mode. This flag is set to false by <tt>config.threadsafe!</tt>.</li>
189
+ </ul>
190
+ <ul>
191
+ <li><tt>config.eager_load_paths</tt> accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the <tt>app</tt> directory of the application.</li>
192
+ </ul>
193
+ <ul>
194
+ <li><tt>config.encoding</tt> sets up the application-wide encoding. Defaults to <span class="caps">UTF</span>-8.</li>
195
+ </ul>
196
+ <ul>
197
+ <li><tt>config.filter_parameters</tt> used for filtering out the parameters that you don&#8217;t want shown in the logs, such as passwords or credit card numbers.</li>
198
+ </ul>
199
+ <ul>
200
+ <li><tt>config.force_ssl</tt> forces all requests to be under <span class="caps">HTTPS</span> protocol by using <tt>Rack::SSL</tt> middleware.</li>
201
+ </ul>
202
+ <ul>
203
+ <li><tt>config.log_level</tt> defines the verbosity of the Rails logger. This option defaults to <tt>:debug</tt> for all modes except production, where it defaults to <tt>:info</tt>.</li>
204
+ </ul>
205
+ <ul>
206
+ <li><tt>config.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby <tt>Logger</tt> class. Defaults to an instance of <tt>ActiveSupport::BufferedLogger</tt>, with auto flushing off in production mode.</li>
207
+ </ul>
208
+ <ul>
209
+ <li><tt>config.middleware</tt> allows you to configure the application&#8217;s middleware. This is covered in depth in the <a href="#configuring-middleware">Configuring Middleware</a> section below.</li>
210
+ </ul>
211
+ <ul>
212
+ <li><tt>config.plugins</tt> accepts the list of plugins to load. The default is <tt>nil</tt> in which case all plugins will be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise, plugins will be loaded in the order specified. This option lets you enforce some particular loading order, useful when dependencies between plugins require it. For that use case, put first the plugins you want to be loaded in a certain order, and then the special symbol <tt>:all</tt> to have the rest loaded without the need to specify them.</li>
213
+ </ul>
214
+ <ul>
215
+ <li><tt>config.preload_frameworks</tt> enables or disables preloading all frameworks at startup. Enabled by <tt>config.threadsafe!</tt>. Defaults to <tt>nil</tt>, so is disabled.</li>
216
+ </ul>
217
+ <ul>
218
+ <li><tt>config.reload_plugins</tt> enables or disables plugin reloading. Defaults to false.</li>
219
+ </ul>
220
+ <ul>
221
+ <li><tt>config.secret_token</tt> used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get <tt>config.secret_token</tt> initialized to a random key in <tt>config/initializers/secret_token.rb</tt>.</li>
222
+ </ul>
223
+ <ul>
224
+ <li><tt>config.serve_static_assets</tt> configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.</li>
225
+ </ul>
226
+ <ul>
227
+ <li><tt>config.session_store</tt> is usually set up in <tt>config/initializers/session_store.rb</tt> and specifies what class to use to store the session. Possible values are <tt>:cookie_store</tt> which is the default, <tt>:mem_cache_store</tt>, and <tt>:disabled</tt>. The last one tells Rails not to deal with sessions. Custom session stores can also be specified:</li>
228
+ </ul>
229
+ <div class="code_container">
230
+ <pre class="brush: ruby; gutter: false; toolbar: false">
231
+ config.session_store :my_custom_store
232
+ </pre>
233
+ </div>
234
+ <p>This custom store must be defined as <tt>ActionDispatch::Session::MyCustomStore</tt>. In addition to symbols, they can also be objects implementing a certain <span class="caps">API</span>, like <tt>ActiveRecord::SessionStore</tt>, in which case no special namespace is required.</p>
235
+ <ul>
236
+ <li><tt>config.threadsafe!</tt> enables <tt>allow_concurrency</tt>, <tt>cache_classes</tt>, <tt>dependency_loading</tt> and <tt>preload_frameworks</tt> to make the application threadsafe.</li>
237
+ </ul>
238
+ <div class="warning"><p>Threadsafe operation is incompatible with the normal workings of development mode Rails. In particular, automatic dependency loading and class reloading are automatically disabled when you call <tt>config.threadsafe!</tt>.</p></div>
239
+ <ul>
240
+ <li><tt>config.time_zone</tt> sets the default time zone for the application and enables time zone awareness for Active Record.</li>
241
+ </ul>
242
+ <ul>
243
+ <li><tt>config.whiny_nils</tt> enables or disables warnings when a certain set of methods are invoked on <tt>nil</tt> and it does not respond to them. Defaults to true in development and test environments.</li>
244
+ </ul>
245
+ <h4 id="configuring-assets">3.2 Configuring Assets</h4>
246
+ <p>Rails 3.1, by default, is set up to use the <tt>sprockets</tt> gem to manage assets within an application. This gem concatenates and compresses assets in order to make serving them much less painful.</p>
247
+ <ul>
248
+ <li><tt>config.assets.enabled</tt> a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in <tt>config/application.rb</tt>.</li>
249
+ </ul>
250
+ <ul>
251
+ <li><tt>config.assets.compress</tt> a flag that enables the compression of compiled assets. It is explicitly set to true in <tt>config/production.rb</tt>.</li>
252
+ </ul>
253
+ <ul>
254
+ <li><tt>config.assets.css_compressor</tt> defines the <span class="caps">CSS</span> compressor to use. It is set by default by <tt>sass-rails</tt>. The unique alternative value at the moment is <tt>:yui</tt>, which uses the <tt>yui-compressor</tt> gem.</li>
255
+ </ul>
256
+ <ul>
257
+ <li><tt>config.assets.js_compressor</tt> defines the JavaScript compressor to use. Possible values are <tt>:closure</tt>, <tt>:uglifier</tt> and <tt>:yui</tt> which require the use of the <tt>closure-compiler</tt>, <tt>uglifier</tt> or <tt>yui-compressor</tt> gems respectively.</li>
258
+ </ul>
259
+ <ul>
260
+ <li><tt>config.assets.paths</tt> contains the paths which are used to look for assets. Appending paths to this configuration option will cause those paths to be used in the search for assets.</li>
261
+ </ul>
262
+ <ul>
263
+ <li><tt>config.assets.precompile</tt> allows you to specify additional assets (other than <tt>application.css</tt> and <tt>application.js</tt>) which are to be precompiled when <tt>rake assets:precompile</tt> is run.</li>
264
+ </ul>
265
+ <ul>
266
+ <li><tt>config.assets.prefix</tt> defines the prefix where assets are served from. Defaults to <tt>/assets</tt>.</li>
267
+ </ul>
268
+ <ul>
269
+ <li><tt>config.assets.digest</tt> enables the use of MD5 fingerprints in asset names. Set to <tt>true</tt> by default in <tt>production.rb</tt>.</li>
270
+ </ul>
271
+ <ul>
272
+ <li><tt>config.assets.debug</tt> disables the concatenation and compression of assets. Set to <tt>false</tt> by default in <tt>development.rb</tt>.</li>
273
+ </ul>
274
+ <ul>
275
+ <li><tt>config.assets.manifest</tt> defines the full path to be used for the asset precompiler&#8217;s manifest file. Defaults to using <tt>config.assets.prefix</tt>.</li>
276
+ </ul>
277
+ <ul>
278
+ <li><tt>config.assets.cache_store</tt> defines the cache store that Sprockets will use. The default is the Rails file store.</li>
279
+ </ul>
280
+ <ul>
281
+ <li><tt>config.assets.version</tt> is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.</li>
282
+ </ul>
283
+ <ul>
284
+ <li><tt>config.assets.compile</tt> is a boolean that can be used to turn on live Sprockets compilation in production.</li>
285
+ </ul>
286
+ <h4 id="configuring-generators">3.3 Configuring Generators</h4>
287
+ <p>Rails 3 allows you to alter what generators are used with the <tt>config.generators</tt> method. This method takes a block:</p>
288
+ <div class="code_container">
289
+ <pre class="brush: ruby; gutter: false; toolbar: false">
290
+ config.generators do |g|
291
+ g.orm :active_record
292
+ g.test_framework :test_unit
293
+ end
294
+ </pre>
295
+ </div>
296
+ <p>The full set of methods that can be used in this block are as follows:</p>
297
+ <ul>
298
+ <li><tt>assets</tt> allows to create assets on generating a scaffold. Defaults to <tt>true</tt>.</li>
299
+ <li><tt>force_plural</tt> allows pluralized model names. Defaults to <tt>false</tt>.</li>
300
+ <li><tt>helper</tt> defines whether or not to generate helpers. Defaults to <tt>true</tt>.</li>
301
+ <li><tt>integration_tool</tt> defines which integration tool to use. Defaults to <tt>nil</tt>.</li>
302
+ <li><tt>javascripts</tt> turns on the hook for javascripts in generators. Used in Rails for when the <tt>scaffold</tt> generator is ran. Defaults to <tt>true</tt>.</li>
303
+ <li><tt>javascript_engine</tt> configures the engine to be used (for eg. coffee) when generating assets. Defaults to <tt>nil</tt>.</li>
304
+ <li><tt>orm</tt> defines which orm to use. Defaults to <tt>false</tt> and will use Active Record by default.</li>
305
+ <li><tt>performance_tool</tt> defines which performance tool to use. Defaults to <tt>nil</tt>.</li>
306
+ <li><tt>resource_controller</tt> defines which generator to use for generating a controller when using <tt>rails generate resource</tt>. Defaults to <tt>:controller</tt>.</li>
307
+ <li><tt>scaffold_controller</tt> different from <tt>resource_controller</tt>, defines which generator to use for generating a <em>scaffolded</em> controller when using <tt>rails generate scaffold</tt>. Defaults to <tt>:scaffold_controller</tt>.</li>
308
+ <li><tt>stylesheets</tt> turns on the hook for stylesheets in generators. Used in Rails for when the <tt>scaffold</tt> generator is ran, but this hook can be used in other generates as well. Defaults to <tt>true</tt>.</li>
309
+ <li><tt>stylesheet_engine</tt> configures the stylesheet engine (for eg. sass) to be used when generating assets. Defaults to <tt>:css</tt>.</li>
310
+ <li><tt>test_framework</tt> defines which test framework to use. Defaults to <tt>false</tt> and will use Test::Unit by default.</li>
311
+ <li><tt>template_engine</tt> defines which template engine to use, such as <span class="caps">ERB</span> or Haml. Defaults to <tt>:erb</tt>.</li>
312
+ </ul>
313
+ <h4 id="configuring-middleware">3.4 Configuring Middleware</h4>
314
+ <p>Every Rails application comes with a standard set of middleware which it uses in this order in the development environment:</p>
315
+ <ul>
316
+ <li><tt>Rack::SSL</tt> forces every request to be under <span class="caps">HTTPS</span> protocol. Will be available if <tt>config.force_ssl</tt> is set to <tt>true</tt>. Options passed to this can be configured by using <tt>config.ssl_options</tt>.</li>
317
+ <li><tt>ActionDispatch::Static</tt> is used to serve static assets. Disabled if <tt>config.serve_static_assets</tt> is <tt>true</tt>.</li>
318
+ <li><tt>Rack::Lock</tt> wraps the app in mutex so it can only be called by a single thread at a time. Only enabled if <tt>config.action_controller.allow_concurrency</tt> is set to <tt>false</tt>, which it is by default.</li>
319
+ <li><tt>ActiveSupport::Cache::Strategy::LocalCache</tt> serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.</li>
320
+ <li><tt>Rack::Runtime</tt> sets an <tt>X-Runtime</tt> header, containing the time (in seconds) taken to execute the request.</li>
321
+ <li><tt>Rails::Rack::Logger</tt> notifies the logs that the request has began. After request is complete, flushes all the logs.</li>
322
+ <li><tt>ActionDispatch::ShowExceptions</tt> rescues any exception returned by the application and renders nice exception pages if the request is local or if <tt>config.consider_all_requests_local</tt> is set to <tt>true</tt>. If <tt>config.action_dispatch.show_exceptions</tt> is set to <tt>false</tt>, exceptions will be raised regardless.</li>
323
+ <li><tt>ActionDispatch::RemoteIp</tt> checks for IP spoofing attacks. Configurable with the <tt>config.action_dispatch.ip_spoofing_check</tt> and <tt>config.action_dispatch.trusted_proxies</tt> settings.</li>
324
+ <li><tt>Rack::Sendfile</tt> intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with <tt>config.action_dispatch.x_sendfile_header</tt>.</li>
325
+ <li><tt>ActionDispatch::Callbacks</tt> runs the prepare callbacks before serving the request.</li>
326
+ <li><tt>ActiveRecord::ConnectionAdapters::ConnectionManagement</tt> cleans active connections after each request, unless the <tt>rack.test</tt> key in the request environment is set to <tt>true</tt>.</li>
327
+ <li><tt>ActiveRecord::QueryCache</tt> caches all <span class="caps">SELECT</span> queries generated in a request. If any <span class="caps">INSERT</span> or <span class="caps">UPDATE</span> takes place then the cache is cleaned.</li>
328
+ <li><tt>ActionDispatch::Cookies</tt> sets cookies for the request.</li>
329
+ <li><tt>ActionDispatch::Session::CookieStore</tt> is responsible for storing the session in cookies. An alternate middleware can be used for this by changing the <tt>config.action_controller.session_store</tt> to an alternate value. Additionally, options passed to this can be configured by using <tt>config.action_controller.session_options</tt>.</li>
330
+ <li><tt>ActionDispatch::Flash</tt> sets up the <tt>flash</tt> keys. Only available if <tt>config.action_controller.session_store</tt> is set to a value.</li>
331
+ <li><tt>ActionDispatch::ParamsParser</tt> parses out parameters from the request into <tt>params</tt>.</li>
332
+ <li><tt>Rack::MethodOverride</tt> allows the method to be overridden if <tt>params[:_method]</tt> is set. This is the middleware which supports the <span class="caps">PUT</span> and <span class="caps">DELETE</span> <span class="caps">HTTP</span> method types.</li>
333
+ <li><tt>ActionDispatch::Head</tt> converts <span class="caps">HEAD</span> requests to <span class="caps">GET</span> requests and serves them as so.</li>
334
+ <li><tt>ActionDispatch::BestStandardsSupport</tt> enables &#8220;best standards support&#8221; so that IE8 renders some elements correctly.</li>
335
+ </ul>
336
+ <p>Besides these usual middleware, you can add your own by using the <tt>config.middleware.use</tt> method:</p>
337
+ <div class="code_container">
338
+ <pre class="brush: ruby; gutter: false; toolbar: false">
339
+ config.middleware.use Magical::Unicorns
340
+ </pre>
341
+ </div>
342
+ <p>This will put the <tt>Magical::Unicorns</tt> middleware on the end of the stack. You can use <tt>insert_before</tt> if you wish to add a middleware before another.</p>
343
+ <div class="code_container">
344
+ <pre class="brush: ruby; gutter: false; toolbar: false">
345
+ config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns
346
+ </pre>
347
+ </div>
348
+ <p>There&#8217;s also <tt>insert_after</tt> which will insert a middleware after another:</p>
349
+ <div class="code_container">
350
+ <pre class="brush: ruby; gutter: false; toolbar: false">
351
+ config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns
352
+ </pre>
353
+ </div>
354
+ <p>Middlewares can also be completely swapped out and replaced with others:</p>
355
+ <div class="code_container">
356
+ <pre class="brush: ruby; gutter: false; toolbar: false">
357
+ config.middleware.swap ActionDispatch::BestStandardsSupport, Magical::Unicorns
358
+ </pre>
359
+ </div>
360
+ <p>They can also be removed from the stack completely:</p>
361
+ <div class="code_container">
362
+ <pre class="brush: ruby; gutter: false; toolbar: false">
363
+ config.middleware.delete ActionDispatch::BestStandardsSupport
364
+ </pre>
365
+ </div>
366
+ <h4 id="configuring-i18n">3.5 Configuring i18n</h4>
367
+ <ul>
368
+ <li><tt>config.i18n.default_locale</tt> sets the default locale of an application used for i18n. Defaults to <tt>:en</tt>.</li>
369
+ </ul>
370
+ <ul>
371
+ <li><tt>config.i18n.load_path</tt> sets the path Rails uses to look for locale files. Defaults to <tt>config/locales/*.{yml,rb}</tt>.</li>
372
+ </ul>
373
+ <h4 id="configuring-active-record">3.6 Configuring Active Record</h4>
374
+ <p><tt>config.active_record</tt> includes a variety of configuration options:</p>
375
+ <ul>
376
+ <li><tt>config.active_record.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then passed on to any new database connections made. You can retrieve this logger by calling <tt>logger</tt> on either an Active Record model class or an Active Record model instance. Set to <tt>nil</tt> to disable logging.</li>
377
+ </ul>
378
+ <ul>
379
+ <li><tt>config.active_record.primary_key_prefix_type</tt> lets you adjust the naming for primary key columns. By default, Rails assumes that primary key columns are named <tt>id</tt> (and this configuration option doesn&#8217;t need to be set.) There are two other choices:
380
+ <ul>
381
+ <li><tt>:table_name</tt> would make the primary key for the Customer class <tt>customerid</tt></li>
382
+ <li><tt>:table_name_with_underscore</tt> would make the primary key for the Customer class <tt>customer_id</tt></li>
383
+ </ul></li>
384
+ </ul>
385
+ <ul>
386
+ <li><tt>config.active_record.table_name_prefix</tt> lets you set a global string to be prepended to table names. If you set this to <tt>northwest_</tt>, then the Customer class will look for <tt>northwest_customers</tt> as its table. The default is an empty string.</li>
387
+ </ul>
388
+ <ul>
389
+ <li><tt>config.active_record.table_name_suffix</tt> lets you set a global string to be appended to table names. If you set this to <tt>_northwest</tt>, then the Customer class will look for <tt>customers_northwest</tt> as its table. The default is an empty string.</li>
390
+ </ul>
391
+ <ul>
392
+ <li><tt>config.active_record.pluralize_table_names</tt> specifies whether Rails will look for singular or plural table names in the database. If set to true (the default), then the Customer class will use the <tt>customers</tt> table. If set to false, then the Customer class will use the <tt>customer</tt> table.</li>
393
+ </ul>
394
+ <ul>
395
+ <li><tt>config.active_record.default_timezone</tt> determines whether to use <tt>Time.local</tt> (if set to <tt>:local</tt>) or <tt>Time.utc</tt> (if set to <tt>:utc</tt>) when pulling dates and times from the database. The default is <tt>:utc</tt> for Rails, although Active Record defaults to <tt>:local</tt> when used outside of Rails.</li>
396
+ </ul>
397
+ <ul>
398
+ <li><tt>config.active_record.schema_format</tt> controls the format for dumping the database schema to a file. The options are <tt>:ruby</tt> (the default) for a database-independent version that depends on migrations, or <tt>:sql</tt> for a set of (potentially database-dependent) <span class="caps">SQL</span> statements.</li>
399
+ </ul>
400
+ <ul>
401
+ <li><tt>config.active_record.timestamped_migrations</tt> controls whether migrations are numbered with serial integers or with timestamps. The default is true, to use timestamps, which are preferred if there are multiple developers working on the same application.</li>
402
+ </ul>
403
+ <ul>
404
+ <li><tt>config.active_record.lock_optimistically</tt> controls whether Active Record will use optimistic locking and is true by default.</li>
405
+ </ul>
406
+ <ul>
407
+ <li><tt>config.active_record.whitelist_attributes</tt> will create an empty whitelist of attributes available for mass-assignment security for all models in your app.</li>
408
+ </ul>
409
+ <p>The MySQL adapter adds one additional configuration option:</p>
410
+ <ul>
411
+ <li><tt>ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans</tt> controls whether Active Record will consider all <tt>tinyint(1)</tt> columns in a MySQL database to be booleans and is true by default.</li>
412
+ </ul>
413
+ <p>The schema dumper adds one additional configuration option:</p>
414
+ <ul>
415
+ <li><tt>ActiveRecord::SchemaDumper.ignore_tables</tt> accepts an array of tables that should <em>not</em> be included in any generated schema file. This setting is ignored unless <tt>config.active_record.schema_format == :ruby</tt>.</li>
416
+ </ul>
417
+ <h4 id="configuring-action-controller">3.7 Configuring Action Controller</h4>
418
+ <p><tt>config.action_controller</tt> includes a number of configuration settings:</p>
419
+ <ul>
420
+ <li><tt>config.action_controller.asset_host</tt> sets the host for the assets. Useful when CDNs are used for hosting assets rather than the application server itself.</li>
421
+ </ul>
422
+ <ul>
423
+ <li><tt>config.action_controller.asset_path</tt> takes a block which configures where assets can be found. Shorter version of <tt>config.action_controller.asset_path</tt>.</li>
424
+ </ul>
425
+ <ul>
426
+ <li><tt>config.action_controller.page_cache_directory</tt> should be the document root for the web server and is set using <tt>Base.page_cache_directory = &#8220;/document/root&#8221;</tt>. For Rails, this directory has already been set to <tt>Rails.public_path</tt> (which is usually set to <tt>Rails.root + &#8220;/public&#8221;</tt>). Changing this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your web server to look in the new location for cached files.</li>
427
+ </ul>
428
+ <ul>
429
+ <li><tt>config.action_controller.page_cache_extension</tt> configures the extension used for cached pages saved to <tt>page_cache_directory</tt>. Defaults to <tt>.html</tt>.</li>
430
+ </ul>
431
+ <ul>
432
+ <li><tt>config.action_controller.perform_caching</tt> configures whether the application should perform caching or not. Set to false in development mode, true in production.</li>
433
+ </ul>
434
+ <ul>
435
+ <li><tt>config.action_controller.default_charset</tt> specifies the default character set for all renders. The default is &#8220;utf-8&#8221;.</li>
436
+ </ul>
437
+ <ul>
438
+ <li><tt>config.action_controller.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then used to log information from Action Controller. Set to <tt>nil</tt> to disable logging.</li>
439
+ </ul>
440
+ <ul>
441
+ <li><tt>config.action_controller.request_forgery_protection_token</tt> sets the token parameter name for RequestForgery. Calling <tt>protect_from_forgery</tt> sets it to <tt>:authenticity_token</tt> by default.</li>
442
+ </ul>
443
+ <ul>
444
+ <li><tt>config.action_controller.allow_forgery_protection</tt> enables or disables <span class="caps">CSRF</span> protection. By default this is false in test mode and true in all other modes.</li>
445
+ </ul>
446
+ <ul>
447
+ <li><tt>config.action_controller.relative_url_root</tt> can be used to tell Rails that you are deploying to a subdirectory. The default is <tt>ENV['RAILS_RELATIVE_URL_ROOT']</tt>.</li>
448
+ </ul>
449
+ <p>The caching code adds two additional settings:</p>
450
+ <ul>
451
+ <li><tt>ActionController::Base.page_cache_directory</tt> sets the directory where Rails will create cached pages for your web server. The default is <tt>Rails.public_path</tt> (which is usually set to <tt>Rails.root + &#8220;/public&#8221;</tt>).</li>
452
+ </ul>
453
+ <ul>
454
+ <li><tt>ActionController::Base.page_cache_extension</tt> sets the extension to be used when generating pages for the cache (this is ignored if the incoming request already has an extension). The default is <tt>.html</tt>.</li>
455
+ </ul>
456
+ <p>The Active Record session store can also be configured:</p>
457
+ <ul>
458
+ <li><tt>ActiveRecord::SessionStore::Session.table_name</tt> sets the name of the table used to store sessions. Defaults to <tt>sessions</tt>.</li>
459
+ </ul>
460
+ <ul>
461
+ <li><tt>ActiveRecord::SessionStore::Session.primary_key</tt> sets the name of the ID column used in the sessions table. Defaults to <tt>session_id</tt>.</li>
462
+ </ul>
463
+ <ul>
464
+ <li><tt>ActiveRecord::SessionStore::Session.data_column_name</tt> sets the name of the column which stores marshaled session data. Defaults to <tt>data</tt>.</li>
465
+ </ul>
466
+ <h4 id="configuring-action-dispatch">3.8 Configuring Action Dispatch</h4>
467
+ <ul>
468
+ <li><tt>config.action_dispatch.session_store</tt> sets the name of the store for session data. The default is <tt>:cookie_store</tt>; other valid options include <tt>:active_record_store</tt>, <tt>:mem_cache_store</tt> or the name of your own custom class.</li>
469
+ </ul>
470
+ <ul>
471
+ <li><tt>config.action_dispatch.tld_length</tt> sets the <span class="caps">TLD</span> (top-level domain) length for the application. Defaults to <tt>1</tt>.</li>
472
+ </ul>
473
+ <ul>
474
+ <li><tt>ActionDispatch::Callbacks.before</tt> takes a block of code to run before the request.</li>
475
+ </ul>
476
+ <ul>
477
+ <li><tt>ActionDispatch::Callbacks.to_prepare</tt> takes a block to run after <tt>ActionDispatch::Callbacks.before</tt>, but before the request. Runs for every request in <tt>development</tt> mode, but only once for <tt>production</tt> or environments with <tt>cache_classes</tt> set to <tt>true</tt>.</li>
478
+ </ul>
479
+ <ul>
480
+ <li><tt>ActionDispatch::Callbacks.after</tt> takes a block of code to run after the request.</li>
481
+ </ul>
482
+ <h4 id="configuring-action-view">3.9 Configuring Action View</h4>
483
+ <p>There are only a few configuration options for Action View, starting with four on <tt>ActionView::Base</tt>:</p>
484
+ <ul>
485
+ <li><tt>config.action_view.field_error_proc</tt> provides an <span class="caps">HTML</span> generator for displaying errors that come from Active Record. The default is</li>
486
+ </ul>
487
+ <div class="code_container">
488
+ <pre class="brush: ruby; gutter: false; toolbar: false">
489
+ Proc.new { |html_tag, instance| %Q(&lt;div class=&quot;field_with_errors&quot;&gt;#{html_tag}&lt;/div&gt;).html_safe }
490
+ </pre>
491
+ </div>
492
+ <ul>
493
+ <li><tt>config.action_view.default_form_builder</tt> tells Rails which form builder to use by default. The default is <tt>ActionView::Helpers::FormBuilder</tt>.</li>
494
+ </ul>
495
+ <ul>
496
+ <li><tt>config.action_view.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then used to log information from Action Mailer. Set to <tt>nil</tt> to disable logging.</li>
497
+ </ul>
498
+ <ul>
499
+ <li><tt>config.action_view.erb_trim_mode</tt> gives the trim mode to be used by <span class="caps">ERB</span>. It defaults to <tt>'-'</tt>. See the <a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/"><span class="caps">ERB</span> documentation</a> for more information.</li>
500
+ </ul>
501
+ <ul>
502
+ <li><tt>config.action_view.javascript_expansions</tt> is a hash containing expansions that can be used for the JavaScript include tag. By default, this is defined as:</li>
503
+ </ul>
504
+ <div class="code_container">
505
+ <pre class="brush: ruby; gutter: false; toolbar: false">
506
+ config.action_view.javascript_expansions = { :defaults =&gt; %w(jquery jquery_ujs) }
507
+ </pre>
508
+ </div>
509
+ <p>However, you may add to this by defining others:</p>
510
+ <div class="code_container">
511
+ <pre class="brush: ruby; gutter: false; toolbar: false">
512
+ config.action_view.javascript_expansions[:prototype] = ['prototype', 'effects', 'dragdrop', 'controls']
513
+ </pre>
514
+ </div>
515
+ <p>And can reference in the view with the following code:</p>
516
+ <div class="code_container">
517
+ <pre class="brush: ruby; gutter: false; toolbar: false">
518
+ &lt;%= javascript_include_tag :prototype %&gt;
519
+ </pre>
520
+ </div>
521
+ <ul>
522
+ <li><tt>config.action_view.stylesheet_expansions</tt> works in much the same way as <tt>javascript_expansions</tt>, but has no default key. Keys defined for this hash can be referenced in the view like such:</li>
523
+ </ul>
524
+ <div class="code_container">
525
+ <pre class="brush: ruby; gutter: false; toolbar: false">
526
+ &lt;%= stylesheet_link_tag :special %&gt;
527
+ </pre>
528
+ </div>
529
+ <ul>
530
+ <li><tt>config.action_view.cache_asset_ids</tt> With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running.</li>
531
+ </ul>
532
+ <h4 id="configuring-action-mailer">3.10 Configuring Action Mailer</h4>
533
+ <p>There are a number of settings available on <tt>config.action_mailer</tt>:</p>
534
+ <ul>
535
+ <li><tt>config.action_mailer.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then used to log information from Action Mailer. Set to <tt>nil</tt> to disable logging.</li>
536
+ </ul>
537
+ <ul>
538
+ <li><tt>config.action_mailer.smtp_settings</tt> allows detailed configuration for the <tt>:smtp</tt> delivery method. It accepts a hash of options, which can include any of these options:
539
+ <ul>
540
+ <li><tt>:address</tt> &#8211; Allows you to use a remote mail server. Just change it from its default &#8220;localhost&#8221; setting.</li>
541
+ <li><tt>:port</tt> &#8211; On the off chance that your mail server doesn&#8217;t run on port 25, you can change it.</li>
542
+ <li><tt>:domain</tt> &#8211; If you need to specify a <span class="caps">HELO</span> domain, you can do it here.</li>
543
+ <li><tt>:user_name</tt> &#8211; If your mail server requires authentication, set the username in this setting.</li>
544
+ <li><tt>:password</tt> &#8211; If your mail server requires authentication, set the password in this setting.</li>
545
+ <li><tt>:authentication</tt> &#8211; If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.</li>
546
+ </ul></li>
547
+ </ul>
548
+ <ul>
549
+ <li><tt>config.action_mailer.sendmail_settings</tt> allows detailed configuration for the <tt>sendmail</tt> delivery method. It accepts a hash of options, which can include any of these options:
550
+ <ul>
551
+ <li><tt>:location</tt> &#8211; The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.</li>
552
+ <li><tt>:arguments</tt> &#8211; The command line arguments. Defaults to <tt>-i -t</tt>.</li>
553
+ </ul></li>
554
+ </ul>
555
+ <ul>
556
+ <li><tt>config.action_mailer.raise_delivery_errors</tt> specifies whether to raise an error if email delivery cannot be completed. It defaults to true.</li>
557
+ </ul>
558
+ <ul>
559
+ <li><tt>config.action_mailer.delivery_method</tt> defines the delivery method. The allowed values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>.</li>
560
+ </ul>
561
+ <ul>
562
+ <li><tt>config.action_mailer.perform_deliveries</tt> specifies whether mail will actually be delivered and is true by default. It can be convenient to set it to false for testing.</li>
563
+ </ul>
564
+ <ul>
565
+ <li><tt>config.action_mailer.default</tt> configures Action Mailer defaults. These default to:
566
+ <div class="code_container">
567
+ <pre class="brush: ruby; gutter: false; toolbar: false">
568
+ :mime_version =&gt; &quot;1.0&quot;,
569
+ :charset =&gt; &quot;UTF-8&quot;,
570
+ :content_type =&gt; &quot;text/plain&quot;,
571
+ :parts_order =&gt; [ &quot;text/plain&quot;, &quot;text/enriched&quot;, &quot;text/html&quot; ]
572
+ </pre>
573
+ </div>
574
+ </li>
575
+ </ul>
576
+ <ul>
577
+ <li><tt>config.action_mailer.observers</tt> registers observers which will be notified when mail is delivered.
578
+ <div class="code_container">
579
+ <pre class="brush: ruby; gutter: false; toolbar: false">
580
+ config.action_mailer.observers = [&quot;MailObserver&quot;]
581
+ </pre>
582
+ </div>
583
+ </li>
584
+ </ul>
585
+ <ul>
586
+ <li><tt>config.action_mailer.interceptors</tt> registers interceptors which will be called before mail is sent.
587
+ <div class="code_container">
588
+ <pre class="brush: ruby; gutter: false; toolbar: false">
589
+ config.action_mailer.interceptors = [&quot;MailInterceptor&quot;]
590
+ </pre>
591
+ </div>
592
+ </li>
593
+ </ul>
594
+ <h4 id="configuring-active-resource">3.11 Configuring Active Resource</h4>
595
+ <p>There is a single configuration setting available on <tt>config.active_resource</tt>:</p>
596
+ <ul>
597
+ <li><tt>config.active_resource.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then used to log information from Active Resource. Set to <tt>nil</tt> to disable logging.</li>
598
+ </ul>
599
+ <h4 id="configuring-active-support">3.12 Configuring Active Support</h4>
600
+ <p>There are a few configuration options available in Active Support:</p>
601
+ <ul>
602
+ <li><tt>config.active_support.bare</tt> enables or disables the loading of <tt>active_support/all</tt> when booting Rails. Defaults to <tt>nil</tt>, which means <tt>active_support/all</tt> is loaded.</li>
603
+ </ul>
604
+ <ul>
605
+ <li><tt>config.active_support.escape_html_entities_in_json</tt> enables or disables the escaping of <span class="caps">HTML</span> entities in <span class="caps">JSON</span> serialization. Defaults to <tt>true</tt>.</li>
606
+ </ul>
607
+ <ul>
608
+ <li><tt>config.active_support.use_standard_json_time_format</tt> enables or disables serializing dates to <span class="caps">ISO</span> 8601 format. Defaults to <tt>false</tt>.</li>
609
+ </ul>
610
+ <ul>
611
+ <li><tt>ActiveSupport::BufferedLogger.silencer</tt> is set to <tt>false</tt> to disable the ability to silence logging in a block. The default is <tt>true</tt>.</li>
612
+ </ul>
613
+ <ul>
614
+ <li><tt>ActiveSupport::Cache::Store.logger</tt> specifies the logger to use within cache store operations.</li>
615
+ </ul>
616
+ <ul>
617
+ <li><tt>ActiveSupport::Deprecation.behavior</tt> alternative setter to <tt>config.active_support.deprecation</tt> which configures the behavior of deprecation warnings for Rails.</li>
618
+ </ul>
619
+ <ul>
620
+ <li><tt>ActiveSupport::Deprecation.silence</tt> takes a block in which all deprecation warnings are silenced.</li>
621
+ </ul>
622
+ <ul>
623
+ <li><tt>ActiveSupport::Deprecation.silenced</tt> sets whether or not to display deprecation warnings.</li>
624
+ </ul>
625
+ <ul>
626
+ <li><tt>ActiveSupport::Logger.silencer</tt> is set to <tt>false</tt> to disable the ability to silence logging in a block. The default is <tt>true</tt>.</li>
627
+ </ul>
628
+ <h3 id="rails-environment-settings">4 Rails Environment Settings</h3>
629
+ <p>Some parts of Rails can also be configured externally by supplying environment variables. The following environment variables are recognized by various parts of Rails:</p>
630
+ <ul>
631
+ <li><tt>ENV["RAILS_ENV"]</tt> defines the Rails environment (production, development, test, and so on) that Rails will run under.</li>
632
+ </ul>
633
+ <ul>
634
+ <li><tt>ENV["RAILS_RELATIVE_URL_ROOT"]</tt> is used by the routing code to recognize URLs when you deploy your application to a subdirectory.</li>
635
+ </ul>
636
+ <ul>
637
+ <li><tt>ENV["RAILS_ASSET_ID"]</tt> will override the default cache-busting timestamps that Rails generates for downloadable assets.</li>
638
+ </ul>
639
+ <ul>
640
+ <li><tt>ENV["RAILS_CACHE_ID"]</tt> and <tt>ENV["RAILS_APP_VERSION"]</tt> are used to generate expanded cache keys in Rails&#8217; caching code. This allows you to have multiple separate caches from the same application.</li>
641
+ </ul>
642
+ <h3 id="using-initializer-files">5 Using Initializer Files</h3>
643
+ <p>After loading the framework and any gems and plugins in your application, Rails turns to loading initializers. An initializer is any Ruby file stored under <tt>config/initializers</tt> in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks, plugins and gems are loaded, such as options to configure settings for these parts.</p>
644
+ <div class="note"><p>You can use subfolders to organize your initializers if you like, because Rails will look into the whole file hierarchy from the initializers folder on down.</p></div>
645
+ <div class="info"><p>If you have any ordering dependency in your initializers, you can control the load order by naming. For example, <tt>01_critical.rb</tt> will be loaded before <tt>02_normal.rb</tt>.</p></div>
646
+ <h3 id="initialization-events">6 Initialization events</h3>
647
+ <p>Rails has 5 initialization events which can be hooked into (listed in the order that they are ran):</p>
648
+ <ul>
649
+ <li><tt>before_configuration</tt>: This is run as soon as the application constant inherits from <tt>Rails::Application</tt>. The <tt>config</tt> calls are evaluated before this happens.</li>
650
+ </ul>
651
+ <ul>
652
+ <li><tt>before_initialize</tt>: This is run directly before the initialization process of the application occurs with the <tt>:bootstrap_hook</tt> initializer near the beginning of the Rails initialization process.</li>
653
+ </ul>
654
+ <ul>
655
+ <li><tt>to_prepare</tt>: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built. More importantly, will run upon every request in <tt>development</tt>, but only once (during boot-up) in <tt>production</tt> and <tt>test</tt>.</li>
656
+ </ul>
657
+ <ul>
658
+ <li><tt>before_eager_load</tt>: This is run directly before eager loading occurs, which is the default behaviour for the <em>production</em> environment and not for the <tt>development</tt> environment.</li>
659
+ </ul>
660
+ <ul>
661
+ <li><tt>after_initialize</tt>: Run directly after the initialization of the application, but before the application initializers are run.</li>
662
+ </ul>
663
+ <p>To define an event for these hooks, use the block syntax within a <tt>Rails::Aplication</tt>, <tt>Rails::Railtie</tt> or <tt>Rails::Engine</tt> subclass:</p>
664
+ <div class="code_container">
665
+ <pre class="brush: ruby; gutter: false; toolbar: false">
666
+ module YourApp
667
+ class Application &lt; Rails::Application
668
+ config.before_initialize do
669
+ # initialization code goes here
670
+ end
671
+ end
672
+ end
673
+ </pre>
674
+ </div>
675
+ <p>Alternatively, you can also do it through the <tt>config</tt> method on the <tt>Rails.application</tt> object:</p>
676
+ <div class="code_container">
677
+ <pre class="brush: ruby; gutter: false; toolbar: false">
678
+ Rails.application.config.before_initialize do
679
+ # initialization code goes here
680
+ end
681
+ </pre>
682
+ </div>
683
+ <div class="warning"><p>Some parts of your application, notably observers and routing, are not yet set up at the point where the <tt>after_initialize</tt> block is called.</p></div>
684
+ <h4 id="rails-railtie-initializer">6.1 <tt>Rails::Railtie#initializer</tt></h4>
685
+ <p>Rails has several initializers that run on startup that are all defined by using the <tt>initializer</tt> method from <tt>Rails::Railtie</tt>. Here&#8217;s an example of the <tt>initialize_whiny_nils</tt> initializer from Active Support:</p>
686
+ <div class="code_container">
687
+ <pre class="brush: ruby; gutter: false; toolbar: false">
688
+ initializer &quot;active_support.initialize_whiny_nils&quot; do |app|
689
+ require 'active_support/whiny_nil' if app.config.whiny_nils
690
+ end
691
+ </pre>
692
+ </div>
693
+ <p>The <tt>initializer</tt> method takes three arguments with the first being the name for the initializer and the second being an options hash (not shown here) and the third being a block. The <tt>:before</tt> key in the options hash can be specified to specify which initializer this new initializer must run before, and the <tt>:after</tt> key will specify which initializer to run this initializer <em>after</em>.</p>
694
+ <p>Initializers defined using the <tt>initializer</tt> method will be ran in the order they are defined in, with the exception of ones that use the <tt>:before</tt> or <tt>:after</tt> methods.</p>
695
+ <div class="warning"><p>You may put your initializer before or after any other initializer in the chain, as long as it is logical. Say you have 4 initializers called &#8220;one&#8221; through &#8220;four&#8221; (defined in that order) and you define &#8220;four&#8221; to go <em>before</em> &#8220;four&#8221; but <em>after</em> &#8220;three&#8221;, that just isn&#8217;t logical and Rails will not be able to determine your initializer order.</p></div>
696
+ <p>The block argument of the <tt>initializer</tt> method is the instance of the application itself, and so we can access the configuration on it by using the <tt>config</tt> method as done in the example.</p>
697
+ <p>Because <tt>Rails::Application</tt> inherits from <tt>Rails::Railtie</tt> (indirectly), you can use the <tt>initializer</tt> method in <tt>config/application.rb</tt> to define initializers for the application.</p>
698
+ <h4 id="initializers">6.2 Initializers</h4>
699
+ <p>Below is a comprehensive list of all the initializers found in Rails in the order that they are defined (and therefore run in, unless otherwise stated).</p>
700
+ <p><strong><tt>load_environment_hook</tt></strong>
701
+ Serves as a placeholder so that <tt>:load_environment_config</tt> can be defined to run before it.</p>
702
+ <p><strong><tt>load_active_support</tt></strong> Requires <tt>active_support/dependencies</tt> which sets up the basis for Active Support. Optionally requires <tt>active_support/all</tt> if <tt>config.active_support.bare</tt> is un-truthful, which is the default.</p>
703
+ <p><strong><tt>preload_frameworks</tt></strong> Loads all autoload dependencies of Rails automatically if <tt>config.preload_frameworks</tt> is <tt>true</tt> or &#8220;truthful&#8221;. By default this configuration option is disabled. In Rails, when internal classes are referenced for the first time they are autoloaded. <tt>:preload_frameworks</tt> loads all of this at once on initialization.</p>
704
+ <p><strong><tt>initialize_logger</tt></strong> Initializes the logger (an <tt>ActiveSupport::BufferedLogger</tt> object) for the application and makes it accessible at <tt>Rails.logger</tt>, provided that no initializer inserted before this point has defined <tt>Rails.logger</tt>.</p>
705
+ <p><strong><tt>initialize_cache</tt></strong> If <tt>RAILS_CACHE</tt> isn&#8217;t set yet, initializes the cache by referencing the value in <tt>config.cache_store</tt> and stores the outcome as <tt>RAILS_CACHE</tt>. If this object responds to the <tt>middleware</tt> method, its middleware is inserted before <tt>Rack::Runtime</tt> in the middleware stack.</p>
706
+ <p><strong><tt>set_clear_dependencies_hook</tt></strong> Provides a hook for <tt>active_record.set_dispatch_hooks</tt> to use, which will run before this initializer. This initializer &#8212; which runs only if <tt>cache_classes</tt> is set to <tt>false</tt> &#8212; uses <tt>ActionDispatch::Callbacks.after</tt> to remove the constants which have been referenced during the request from the object space so that they will be reloaded during the following request.</p>
707
+ <p><strong><tt>initialize_dependency_mechanism</tt></strong> If <tt>config.cache_classes</tt> is true, configures <tt>ActiveSupport::Dependencies.mechanism</tt> to <tt>require</tt> dependencies rather than <tt>load</tt> them.</p>
708
+ <p><strong><tt>bootstrap_hook</tt></strong> Runs all configured <tt>before_initialize</tt> blocks.</p>
709
+ <p><strong><tt>i18n.callbacks</tt></strong> In the development environment, sets up a <tt>to_prepare</tt> callback which will call <tt>I18n.reload!</tt> if any of the locales have changed since the last request. In production mode this callback will only run on the first request.</p>
710
+ <p><strong><tt>active_support.initialize_whiny_nils</tt></strong> Requires <tt>active_support/whiny_nil</tt> if <tt>config.whiny_nils</tt> is true. This file will output errors such as:</p>
711
+ <div class="code_container">
712
+ <pre class="brush: plain; gutter: false; toolbar: false">
713
+ Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
714
+ </pre>
715
+ </div>
716
+ <p>And:</p>
717
+ <div class="code_container">
718
+ <pre class="brush: plain; gutter: false; toolbar: false">
719
+ You have a nil object when you didn't expect it!
720
+ You might have expected an instance of Array.
721
+ The error occurred while evaluating nil.each
722
+ </pre>
723
+ </div>
724
+ <p><strong><tt>active_support.deprecation_behavior</tt></strong> Sets up deprecation reporting for environments, defaulting to <tt>:log</tt> for development, <tt>:notify</tt> for production and <tt>:stderr</tt> for test. If a value isn&#8217;t set for <tt>config.active_support.deprecation</tt> then this initializer will prompt the user to configure this line in the current environment&#8217;s <tt>config/environments</tt> file. Can be set to an array of values.</p>
725
+ <p><strong><tt>active_support.initialize_time_zone</tt></strong> Sets the default time zone for the application based on the <tt>config.time_zone</tt> setting, which defaults to &#8220;<span class="caps">UTC</span>&#8221;.</p>
726
+ <p><strong><tt>action_dispatch.configure</tt></strong> Configures the <tt>ActionDispatch::Http::URL.tld_length</tt> to be set to the value of <tt>config.action_dispatch.tld_length</tt>.</p>
727
+ <p><strong><tt>action_view.cache_asset_ids</tt></strong> Sets <tt>ActionView::Helpers::AssetTagHelper::AssetPaths.cache_asset_ids</tt> to <tt>false</tt> when Active Support loads, but only if <tt>config.cache_classes</tt> is too.</p>
728
+ <p><strong><tt>action_view.javascript_expansions</tt></strong> Registers the expansions set up by <tt>config.action_view.javascript_expansions</tt> and <tt>config.action_view.stylesheet_expansions</tt> to be recognized by Action View and therefore usable in the views.</p>
729
+ <p><strong><tt>action_view.set_configs</tt></strong> Sets up Action View by using the settings in <tt>config.action_view</tt> by <tt>send</tt>&#8217;ing the method names as setters to <tt>ActionView::Base</tt> and passing the values through.</p>
730
+ <p><strong><tt>action_controller.logger</tt></strong> Sets <tt>ActionController::Base.logger</tt> &#8212; if it&#8217;s not already set &#8212; to <tt>Rails.logger</tt>.</p>
731
+ <p><strong><tt>action_controller.initialize_framework_caches</tt></strong> Sets <tt>ActionController::Base.cache_store</tt> &#8212; if it&#8217;s not already set &#8212; to <tt>RAILS_CACHE</tt>.</p>
732
+ <p><strong><tt>action_controller.set_configs</tt></strong> Sets up Action Controller by using the settings in <tt>config.action_controller</tt> by <tt>send</tt>&#8217;ing the method names as setters to <tt>ActionController::Base</tt> and passing the values through.</p>
733
+ <p><strong><tt>action_controller.compile_config_methods</tt></strong> Initializes methods for the config settings specified so that they are quicker to access.</p>
734
+ <p><strong><tt>active_record.initialize_timezone</tt></strong> Sets <tt>ActiveRecord::Base.time_zone_aware_attributes</tt> to true, as well as setting <tt>ActiveRecord::Base.default_timezone</tt> to <span class="caps">UTC</span>. When attributes are read from the database, they will be converted into the time zone specified by <tt>Time.zone</tt>.</p>
735
+ <p><strong><tt>active_record.logger</tt></strong> Sets <tt>ActiveRecord::Base.logger</tt> &#8212; if it&#8217;s not already set &#8212; to <tt>Rails.logger</tt>.</p>
736
+ <p><strong><tt>active_record.set_configs</tt></strong> Sets up Active Record by using the settings in <tt>config.active_record</tt> by <tt>send</tt>&#8217;ing the method names as setters to <tt>ActiveRecord::Base</tt> and passing the values through.</p>
737
+ <p><strong><tt>active_record.initialize_database</tt></strong> Loads the database configuration (by default) from <tt>config/database.yml</tt> and establishes a connection for the current environment.</p>
738
+ <p><strong><tt>active_record.log_runtime</tt></strong> Includes <tt>ActiveRecord::Railties::ControllerRuntime</tt> which is responsible for reporting the time taken by Active Record calls for the request back to the logger.</p>
739
+ <p><strong><tt>active_record.set_dispatch_hooks</tt></strong> Resets all reloadable connections to the database if <tt>config.cache_classes</tt> is set to <tt>false</tt>.</p>
740
+ <p><strong><tt>action_mailer.logger</tt></strong> Sets <tt>ActionMailer::Base.logger</tt> &#8212; if it&#8217;s not already set &#8212; to <tt>Rails.logger</tt>.</p>
741
+ <p><strong><tt>action_mailer.set_configs</tt></strong> Sets up Action Mailer by using the settings in <tt>config.action_mailer</tt> by <tt>send</tt>&#8217;ing the method names as setters to <tt>ActionMailer::Base</tt> and passing the values through.</p>
742
+ <p><strong><tt>action_mailer.compile_config_methods</tt></strong> Initializes methods for the config settings specified so that they are quicker to access.</p>
743
+ <p><strong><tt>active_resource.set_configs</tt></strong> Sets up Active Resource by using the settings in <tt>config.active_resource</tt> by <tt>send</tt>&#8217;ing the method names as setters to <tt>ActiveResource::Base</tt> and passing the values through.</p>
744
+ <p><strong><tt>set_load_path</tt></strong> This initializer runs before <tt>bootstrap_hook</tt>. Adds the <tt>vendor</tt>, <tt>lib</tt>, all directories of <tt>app</tt> and any paths specified by <tt>config.load_paths</tt> to <tt>$LOAD_PATH</tt>.</p>
745
+ <p><strong><tt>set_autoload_paths</tt></strong> This initializer runs before <tt>bootstrap_hook</tt>. Adds all sub-directories of <tt>app</tt> and paths specified by <tt>config.autoload_paths</tt> to <tt>ActiveSupport::Dependencies.autoload_paths</tt>.</p>
746
+ <p><strong><tt>add_routing_paths</tt></strong> Loads (by default) all <tt>config/routes.rb</tt> files (in the application and railties, including engines) and sets up the routes for the application.</p>
747
+ <p><strong><tt>add_locales</tt></strong> Adds the files in <tt>config/locales</tt> (from the application, railties and engines) to <tt>I18n.load_path</tt>, making available the translations in these files.</p>
748
+ <p><strong><tt>add_view_paths</tt></strong> Adds the directory <tt>app/views</tt> from the application, railties and engines to the lookup path for view files for the application.</p>
749
+ <p><strong><tt>load_environment_config</tt></strong> Loads the <tt>config/environments</tt> file for the current environment.</p>
750
+ <p><strong><tt>append_asset_paths</tt></strong> Finds asset paths for the application and all attached railties and keeps a track of the available directories in <tt>config.static_asset_paths</tt>.</p>
751
+ <p><strong><tt>prepend_helpers_path</tt></strong> Adds the directory <tt>app/helpers</tt> from the application, railties and engines to the lookup path for helpers for the application.</p>
752
+ <p><strong><tt>load_config_initializers</tt></strong> Loads all Ruby files from <tt>config/initializers</tt> in the application, railties and engines. The files in this directory can be used to hold configuration settings that should be made after all of the frameworks and plugins are loaded.</p>
753
+ <p><strong><tt>engines_blank_point</tt></strong> Provides a point-in-initialization to hook into if you wish to do anything before engines are loaded. After this point, all railtie and engine initializers are ran.</p>
754
+ <p><strong><tt>add_generator_templates</tt></strong> Finds templates for generators at <tt>lib/templates</tt> for the application, railities and engines and adds these to the <tt>config.generators.templates</tt> setting, which will make the templates available for all generators to reference.</p>
755
+ <p><strong><tt>ensure_autoload_once_paths_as_subset</tt></strong> Ensures that the <tt>config.autoload_once_paths</tt> only contains paths from <tt>config.autoload_paths</tt>. If it contains extra paths, then an exception will be raised.</p>
756
+ <p><strong><tt>add_to_prepare_blocks</tt></strong> The block for every <tt>config.to_prepare</tt> call in the application, a railtie or engine is added to the <tt>to_prepare</tt> callbacks for Action Dispatch which will be ran per request in development, or before the first request in production.</p>
757
+ <p><strong><tt>add_builtin_route</tt></strong> If the application is running under the development environment then this will append the route for <tt>rails/info/properties</tt> to the application routes. This route provides the detailed information such as Rails and Ruby version for <tt>public/index.html</tt> in a default Rails application.</p>
758
+ <p><strong><tt>build_middleware_stack</tt></strong> Builds the middleware stack for the application, returning an object which has a <tt>call</tt> method which takes a Rack environment object for the request.</p>
759
+ <p><strong><tt>eager_load!</tt></strong> If <tt>config.cache_classes</tt> is true, runs the <tt>config.before_eager_load</tt> hooks and then calls <tt>eager_load!</tt> which will load all the Ruby files from <tt>config.eager_load_paths</tt>.</p>
760
+ <p><strong><tt>finisher_hook</tt></strong> Provides a hook for after the initialization of process of the application is complete, as well as running all the <tt>config.after_initialize</tt> blocks for the application, railties and engines.</p>
761
+ <p><strong><tt>set_routes_reloader</tt></strong> Configures Action Dispatch to reload the routes file using <tt>ActionDispatch::Callbacks.to_prepare</tt>.</p>
762
+ <p><strong><tt>disable_dependency_loading</tt></strong> Disables the automatic dependency loading if the <tt>config.cache_classes</tt> is set to true and <tt>config.dependency_loading</tt> is set to false.</p>
763
+
764
+ <h3>Feedback</h3>
765
+ <p>
766
+ You're encouraged to help improve the quality of this guide.
767
+ </p>
768
+ <p>
769
+ If you see any typos or factual errors you are confident to
770
+ patch, please clone <a href="https://github.com/lifo/docrails">docrails</a>
771
+ and push the change yourself. That branch of Rails has public write access.
772
+ Commits are still reviewed, but that happens after you've submitted your
773
+ contribution. <a href="https://github.com/lifo/docrails">docrails</a> is
774
+ cross-merged with master periodically.
775
+ </p>
776
+ <p>
777
+ You may also find incomplete content, or stuff that is not up to date.
778
+ Please do add any missing documentation for master. Check the
779
+ <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
780
+ for style and conventions.
781
+ </p>
782
+ <p>
783
+ If for whatever reason you spot something to fix but cannot patch it yourself, please
784
+ <a href="https://github.com/rails/rails/issues">open an issue</a>.
785
+ </p>
786
+ <p>And last but not least, any kind of discussion regarding Ruby on Rails
787
+ documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
788
+ </p>
789
+ </div>
790
+ </div>
791
+ </div>
792
+
793
+ <hr class="hide" />
794
+ <div id="footer">
795
+ <div class="wrapper">
796
+ <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
797
+ <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
798
+ </div>
799
+ </div>
800
+
801
+ <script type="text/javascript" src="javascripts/guides.js"></script>
802
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
803
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
804
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
805
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
806
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
807
+ <script type="text/javascript">
808
+ SyntaxHighlighter.all()
809
+ </script>
810
+ </body>
811
+ </html>