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.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/guides/Rakefile +3 -1
  3. data/guides/bug_report_templates/action_controller_gem.rb +2 -2
  4. data/guides/bug_report_templates/action_controller_master.rb +2 -2
  5. data/guides/source/3_0_release_notes.md +2 -2
  6. data/guides/source/4_1_release_notes.md +1 -1
  7. data/guides/source/4_2_release_notes.md +250 -225
  8. data/guides/source/_welcome.html.erb +1 -1
  9. data/guides/source/action_controller_overview.md +6 -6
  10. data/guides/source/action_mailer_basics.md +26 -11
  11. data/guides/source/action_view_overview.md +0 -1
  12. data/guides/source/active_job_basics.md +29 -23
  13. data/guides/source/active_record_postgresql.md +2 -7
  14. data/guides/source/active_record_validations.md +1 -0
  15. data/guides/source/active_support_core_extensions.md +1 -1
  16. data/guides/source/active_support_instrumentation.md +5 -5
  17. data/guides/source/asset_pipeline.md +2 -2
  18. data/guides/source/association_basics.md +0 -2
  19. data/guides/source/command_line.md +6 -15
  20. data/guides/source/configuring.md +4 -4
  21. data/guides/source/documents.yaml +0 -1
  22. data/guides/source/engines.md +26 -15
  23. data/guides/source/form_helpers.md +10 -2
  24. data/guides/source/getting_started.md +9 -9
  25. data/guides/source/rails_on_rack.md +2 -2
  26. data/guides/source/ruby_on_rails_guides_guidelines.md +1 -0
  27. data/guides/source/security.md +1 -1
  28. data/guides/source/testing.md +80 -13
  29. data/guides/source/upgrading_ruby_on_rails.md +23 -20
  30. metadata +29 -229
  31. data/guides/output/2_2_release_notes.html +0 -724
  32. data/guides/output/2_3_release_notes.html +0 -870
  33. data/guides/output/3_0_release_notes.html +0 -773
  34. data/guides/output/3_1_release_notes.html +0 -740
  35. data/guides/output/3_2_release_notes.html +0 -797
  36. data/guides/output/4_0_release_notes.html +0 -523
  37. data/guides/output/4_1_release_notes.html +0 -806
  38. data/guides/output/4_2_release_notes.html +0 -728
  39. data/guides/output/Gemfile +0 -6
  40. data/guides/output/_license.html +0 -226
  41. data/guides/output/_welcome.html +0 -233
  42. data/guides/output/action_controller_overview.html +0 -1335
  43. data/guides/output/action_mailer_basics.html +0 -928
  44. data/guides/output/action_view_overview.html +0 -1509
  45. data/guides/output/active_job_basics.html +0 -546
  46. data/guides/output/active_model_basics.html +0 -438
  47. data/guides/output/active_record_basics.html +0 -594
  48. data/guides/output/active_record_callbacks.html +0 -592
  49. data/guides/output/active_record_migrations.html +0 -1123
  50. data/guides/output/active_record_postgresql.html +0 -675
  51. data/guides/output/active_record_querying.html +0 -1796
  52. data/guides/output/active_record_validations.html +0 -1301
  53. data/guides/output/active_support_core_extensions.html +0 -3450
  54. data/guides/output/active_support_instrumentation.html +0 -1121
  55. data/guides/output/api_documentation_guidelines.html +0 -498
  56. data/guides/output/asset_pipeline.html +0 -1167
  57. data/guides/output/association_basics.html +0 -2086
  58. data/guides/output/caching_with_rails.html +0 -553
  59. data/guides/output/command_line.html +0 -791
  60. data/guides/output/configuring.html +0 -1055
  61. data/guides/output/contributing_to_ruby_on_rails.html +0 -657
  62. data/guides/output/credits.html +0 -284
  63. data/guides/output/debugging_rails_applications.html +0 -1014
  64. data/guides/output/development_dependencies_install.html +0 -478
  65. data/guides/output/engines.html +0 -1438
  66. data/guides/output/form_helpers.html +0 -1074
  67. data/guides/output/generators.html +0 -838
  68. data/guides/output/getting_started.html +0 -2092
  69. data/guides/output/i18n.html +0 -1198
  70. data/guides/output/images/akshaysurve.jpg +0 -0
  71. data/guides/output/images/belongs_to.png +0 -0
  72. data/guides/output/images/book_icon.gif +0 -0
  73. data/guides/output/images/bullet.gif +0 -0
  74. data/guides/output/images/chapters_icon.gif +0 -0
  75. data/guides/output/images/check_bullet.gif +0 -0
  76. data/guides/output/images/credits_pic_blank.gif +0 -0
  77. data/guides/output/images/csrf.png +0 -0
  78. data/guides/output/images/edge_badge.png +0 -0
  79. data/guides/output/images/favicon.ico +0 -0
  80. data/guides/output/images/feature_tile.gif +0 -0
  81. data/guides/output/images/footer_tile.gif +0 -0
  82. data/guides/output/images/fxn.png +0 -0
  83. data/guides/output/images/getting_started/article_with_comments.png +0 -0
  84. data/guides/output/images/getting_started/challenge.png +0 -0
  85. data/guides/output/images/getting_started/confirm_dialog.png +0 -0
  86. data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  87. data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  88. data/guides/output/images/getting_started/form_with_errors.png +0 -0
  89. data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
  90. data/guides/output/images/getting_started/new_article.png +0 -0
  91. data/guides/output/images/getting_started/new_post.png +0 -0
  92. data/guides/output/images/getting_started/post_with_comments.png +0 -0
  93. data/guides/output/images/getting_started/rails_welcome.png +0 -0
  94. data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
  95. data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
  96. data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
  97. data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
  98. data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
  99. data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
  100. data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
  101. data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
  102. data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
  103. data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
  104. data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
  105. data/guides/output/images/grey_bullet.gif +0 -0
  106. data/guides/output/images/habtm.png +0 -0
  107. data/guides/output/images/has_many.png +0 -0
  108. data/guides/output/images/has_many_through.png +0 -0
  109. data/guides/output/images/has_one.png +0 -0
  110. data/guides/output/images/has_one_through.png +0 -0
  111. data/guides/output/images/header_backdrop.png +0 -0
  112. data/guides/output/images/header_tile.gif +0 -0
  113. data/guides/output/images/i18n/demo_html_safe.png +0 -0
  114. data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
  115. data/guides/output/images/i18n/demo_translated_en.png +0 -0
  116. data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
  117. data/guides/output/images/i18n/demo_translation_missing.png +0 -0
  118. data/guides/output/images/i18n/demo_untranslated.png +0 -0
  119. data/guides/output/images/icons/README +0 -5
  120. data/guides/output/images/icons/callouts/1.png +0 -0
  121. data/guides/output/images/icons/callouts/10.png +0 -0
  122. data/guides/output/images/icons/callouts/11.png +0 -0
  123. data/guides/output/images/icons/callouts/12.png +0 -0
  124. data/guides/output/images/icons/callouts/13.png +0 -0
  125. data/guides/output/images/icons/callouts/14.png +0 -0
  126. data/guides/output/images/icons/callouts/15.png +0 -0
  127. data/guides/output/images/icons/callouts/2.png +0 -0
  128. data/guides/output/images/icons/callouts/3.png +0 -0
  129. data/guides/output/images/icons/callouts/4.png +0 -0
  130. data/guides/output/images/icons/callouts/5.png +0 -0
  131. data/guides/output/images/icons/callouts/6.png +0 -0
  132. data/guides/output/images/icons/callouts/7.png +0 -0
  133. data/guides/output/images/icons/callouts/8.png +0 -0
  134. data/guides/output/images/icons/callouts/9.png +0 -0
  135. data/guides/output/images/icons/caution.png +0 -0
  136. data/guides/output/images/icons/example.png +0 -0
  137. data/guides/output/images/icons/home.png +0 -0
  138. data/guides/output/images/icons/important.png +0 -0
  139. data/guides/output/images/icons/next.png +0 -0
  140. data/guides/output/images/icons/note.png +0 -0
  141. data/guides/output/images/icons/prev.png +0 -0
  142. data/guides/output/images/icons/tip.png +0 -0
  143. data/guides/output/images/icons/up.png +0 -0
  144. data/guides/output/images/icons/warning.png +0 -0
  145. data/guides/output/images/nav_arrow.gif +0 -0
  146. data/guides/output/images/oscardelben.jpg +0 -0
  147. data/guides/output/images/polymorphic.png +0 -0
  148. data/guides/output/images/radar.png +0 -0
  149. data/guides/output/images/rails4_features.png +0 -0
  150. data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
  151. data/guides/output/images/rails_guides_logo.gif +0 -0
  152. data/guides/output/images/rails_logo_remix.gif +0 -0
  153. data/guides/output/images/session_fixation.png +0 -0
  154. data/guides/output/images/tab_grey.gif +0 -0
  155. data/guides/output/images/tab_info.gif +0 -0
  156. data/guides/output/images/tab_note.gif +0 -0
  157. data/guides/output/images/tab_red.gif +0 -0
  158. data/guides/output/images/tab_yellow.gif +0 -0
  159. data/guides/output/images/tab_yellow.png +0 -0
  160. data/guides/output/images/vijaydev.jpg +0 -0
  161. data/guides/output/index.html +0 -354
  162. data/guides/output/initialization.html +0 -876
  163. data/guides/output/javascripts/guides.js +0 -59
  164. data/guides/output/javascripts/jquery.min.js +0 -4
  165. data/guides/output/javascripts/responsive-tables.js +0 -43
  166. data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  167. data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  168. data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  169. data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  170. data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  171. data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  172. data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  173. data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  174. data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  175. data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  176. data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  177. data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  178. data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  179. data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  180. data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  181. data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  182. data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  183. data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  184. data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  185. data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  186. data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  187. data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  188. data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  189. data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  190. data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  191. data/guides/output/javascripts/syntaxhighlighter/shCore.js +0 -17
  192. data/guides/output/layout.html +0 -448
  193. data/guides/output/layouts_and_rendering.html +0 -1541
  194. data/guides/output/maintenance_policy.html +0 -257
  195. data/guides/output/migrations.html +0 -1360
  196. data/guides/output/nested_model_forms.html +0 -412
  197. data/guides/output/plugins.html +0 -644
  198. data/guides/output/rails_application_templates.html +0 -450
  199. data/guides/output/rails_on_rack.html +0 -547
  200. data/guides/output/routing.html +0 -1631
  201. data/guides/output/ruby_on_rails_guides_guidelines.html +0 -329
  202. data/guides/output/security.html +0 -935
  203. data/guides/output/stylesheets/fixes.css +0 -16
  204. data/guides/output/stylesheets/kindle.css +0 -11
  205. data/guides/output/stylesheets/main.css +0 -713
  206. data/guides/output/stylesheets/print.css +0 -52
  207. data/guides/output/stylesheets/reset.css +0 -43
  208. data/guides/output/stylesheets/responsive-tables.css +0 -50
  209. data/guides/output/stylesheets/style.css +0 -13
  210. data/guides/output/stylesheets/syntaxhighlighter/shCore.css +0 -226
  211. data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  212. data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  213. data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  214. data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  215. data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  216. data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  217. data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  218. data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  219. data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  220. data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  221. data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  222. data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  223. data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  224. data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  225. data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  226. data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  227. data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  228. data/guides/output/testing.html +0 -1350
  229. data/guides/output/upgrading_ruby_on_rails.html +0 -1135
  230. data/guides/output/working_with_javascript_in_rails.html +0 -587
@@ -1,1055 +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>Configuring Rails Applications — 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>Configuring Rails Applications</h2><p>This guide covers the configuration and initialization features available to Rails applications.</p><p>After reading this guide, you will know:</p>
165
- <ul>
166
- <li>How to adjust the behavior of your Rails applications.</li>
167
- <li>How to add additional code to be run at application start time.</li>
168
- </ul>
169
-
170
-
171
- <div id="subCol">
172
- <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
173
- <ol class="chapters">
174
- <li><a href="#locations-for-initialization-code">Locations for Initialization Code</a></li>
175
- <li><a href="#running-code-before-rails">Running Code Before Rails</a></li>
176
- <li>
177
- <a href="#configuring-rails-components">Configuring Rails Components</a>
178
-
179
- <ul>
180
- <li><a href="#rails-general-configuration">Rails General Configuration</a></li>
181
- <li><a href="#configuring-assets">Configuring Assets</a></li>
182
- <li><a href="#configuring-generators">Configuring Generators</a></li>
183
- <li><a href="#configuring-middleware">Configuring Middleware</a></li>
184
- <li><a href="#configuring-i18n">Configuring i18n</a></li>
185
- <li><a href="#configuring-active-record">Configuring Active Record</a></li>
186
- <li><a href="#configuring-action-controller">Configuring Action Controller</a></li>
187
- <li><a href="#configuring-action-dispatch">Configuring Action Dispatch</a></li>
188
- <li><a href="#configuring-action-view">Configuring Action View</a></li>
189
- <li><a href="#configuring-action-mailer">Configuring Action Mailer</a></li>
190
- <li><a href="#configuring-active-support">Configuring Active Support</a></li>
191
- <li><a href="#configuring-a-database">Configuring a Database</a></li>
192
- <li><a href="#connection-preference">Connection Preference</a></li>
193
- <li><a href="#creating-rails-environments">Creating Rails Environments</a></li>
194
- <li><a href="#deploy-to-a-subdirectory-(relative-url-root)">Deploy to a subdirectory (relative url root)</a></li>
195
- </ul>
196
- </li>
197
- <li><a href="#rails-environment-settings">Rails Environment Settings</a></li>
198
- <li><a href="#using-initializer-files">Using Initializer Files</a></li>
199
- <li>
200
- <a href="#initialization-events">Initialization events</a>
201
-
202
- <ul>
203
- <li><a href="#rails::railtie#initializer"><code>Rails::Railtie#initializer</code></a></li>
204
- <li><a href="#initializers">Initializers</a></li>
205
- </ul>
206
- </li>
207
- <li><a href="#database-pooling">Database pooling</a></li>
208
- <li><a href="#custom-configuration">Custom configuration</a></li>
209
- </ol>
210
-
211
- </div>
212
-
213
- </div>
214
- </div>
215
-
216
- <div id="container">
217
- <div class="wrapper">
218
- <div id="mainCol">
219
- <h3 id="locations-for-initialization-code">1 Locations for Initialization Code</h3><p>Rails offers four standard spots to place initialization code:</p>
220
- <ul>
221
- <li><code>config/application.rb</code></li>
222
- <li>Environment-specific configuration files</li>
223
- <li>Initializers</li>
224
- <li>After-initializers</li>
225
- </ul>
226
- <h3 id="running-code-before-rails">2 Running Code Before Rails</h3><p>In the rare event that your application needs to run some code before Rails itself is loaded, put it above the call to <code>require 'rails/all'</code> in <code>config/application.rb</code>.</p><h3 id="configuring-rails-components">3 Configuring Rails Components</h3><p>In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file <code>config/application.rb</code> and environment-specific configuration files (such as <code>config/environments/production.rb</code>) allow you to specify the various settings that you want to pass down to all of the components.</p><p>For example, the <code>config/application.rb</code> file includes this setting:</p><div class="code_container">
227
- <pre class="brush: ruby; gutter: false; toolbar: false">
228
- config.autoload_paths += %W(#{config.root}/extras)
229
-
230
- </pre>
231
- </div>
232
- <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 <code>config</code> object in <code>config/application.rb</code>:</p><div class="code_container">
233
- <pre class="brush: ruby; gutter: false; toolbar: false">
234
- config.active_record.schema_format = :ruby
235
-
236
- </pre>
237
- </div>
238
- <p>Rails will use that particular setting to configure Active Record.</p><h4 id="rails-general-configuration">3.1 Rails General Configuration</h4><p>These configuration methods are to be called on a <code>Rails::Railtie</code> object, such as a subclass of <code>Rails::Engine</code> or <code>Rails::Application</code>.</p>
239
- <ul>
240
- <li>
241
- <p><code>config.after_initialize</code> takes a block which will be run <em>after</em> Rails has finished initializing the application. That includes the initialization of the framework itself, engines, and all the application's initializers in <code>config/initializers</code>. Note that this block <em>will</em> be run for rake tasks. Useful for configuring values set up by other initializers:</p>
242
- <div class="code_container">
243
- <pre class="brush: ruby; gutter: false; toolbar: false">
244
- config.after_initialize do
245
- ActionView::Base.sanitized_allowed_tags.delete 'div'
246
- end
247
-
248
- </pre>
249
- </div>
250
- </li>
251
- <li><p><code>config.asset_host</code> sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints built-in in browsers using different domain aliases. Shorter version of <code>config.action_controller.asset_host</code>.</p></li>
252
- <li><p><code>config.autoload_once_paths</code> accepts an array of paths from which Rails will autoload constants that won't be wiped per request. Relevant if <code>config.cache_classes</code> 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 <code>autoload_paths</code>. Default is an empty array.</p></li>
253
- <li><p><code>config.autoload_paths</code> accepts an array of paths from which Rails will autoload constants. Default is all directories under <code>app</code>.</p></li>
254
- <li><p><code>config.cache_classes</code> 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 <code>threadsafe!</code>.</p></li>
255
- <li><p><code>config.action_view.cache_template_loading</code> controls whether or not templates should be reloaded on each request. Defaults to whatever is set for <code>config.cache_classes</code>.</p></li>
256
- <li><p><code>config.beginning_of_week</code> sets the default beginning of week for the
257
- application. Accepts a valid week day symbol (e.g. <code>:monday</code>).</p></li>
258
- <li><p><code>config.cache_store</code> configures which cache store to use for Rails caching. Options include one of the symbols <code>:memory_store</code>, <code>:file_store</code>, <code>:mem_cache_store</code>, <code>:null_store</code>, or an object that implements the cache API. Defaults to <code>:file_store</code> if the directory <code>tmp/cache</code> exists, and to <code>:memory_store</code> otherwise.</p></li>
259
- <li><p><code>config.colorize_logging</code> specifies whether or not to use ANSI color codes when logging information. Defaults to true.</p></li>
260
- <li><p><code>config.consider_all_requests_local</code> is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the <code>Rails::Info</code> controller will show the application runtime context in <code>/rails/info/properties</code>. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement <code>local_request?</code> in controllers to specify which requests should provide debugging information on errors.</p></li>
261
- <li>
262
- <p><code>config.console</code> allows you to set class that will be used as console you run <code>rails console</code>. It's best to run it in <code>console</code> block:</p>
263
- <div class="code_container">
264
- <pre class="brush: ruby; gutter: false; toolbar: false">
265
- console do
266
- # this block is called only when running console,
267
- # so we can safely require pry here
268
- require "pry"
269
- config.console = Pry
270
- end
271
-
272
- </pre>
273
- </div>
274
- </li>
275
- <li><p><code>config.dependency_loading</code> is a flag that allows you to disable constant autoloading setting it to false. It only has effect if <code>config.cache_classes</code> is true, which it is by default in production mode. This flag is set to false by <code>config.threadsafe!</code>.</p></li>
276
- <li><p><code>config.eager_load</code> when true, eager loads all registered <code>config.eager_load_namespaces</code>. This includes your application, engines, Rails frameworks and any other registered namespace.</p></li>
277
- <li><p><code>config.eager_load_namespaces</code> registers namespaces that are eager loaded when <code>config.eager_load</code> is true. All namespaces in the list must respond to the <code>eager_load!</code> method.</p></li>
278
- <li><p><code>config.eager_load_paths</code> accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the <code>app</code> directory of the application.</p></li>
279
- <li><p><code>config.encoding</code> sets up the application-wide encoding. Defaults to UTF-8.</p></li>
280
- <li><p><code>config.exceptions_app</code> sets the exceptions application invoked by the ShowException middleware when an exception happens. Defaults to <code>ActionDispatch::PublicExceptions.new(Rails.public_path)</code>.</p></li>
281
- <li><p><code>config.file_watcher</code> the class used to detect file updates in the filesystem when <code>config.reload_classes_only_on_change</code> is true. Must conform to <code>ActiveSupport::FileUpdateChecker</code> API.</p></li>
282
- <li><p><code>config.filter_parameters</code> used for filtering out the parameters that
283
- you don't want shown in the logs, such as passwords or credit card
284
- numbers. New applications filter out passwords by adding the following <code>config.filter_parameters+=[:password]</code> in <code>config/initializers/filter_parameter_logging.rb</code>.</p></li>
285
- <li><p><code>config.force_ssl</code> forces all requests to be under HTTPS protocol by using <code>ActionDispatch::SSL</code> middleware.</p></li>
286
- <li><p><code>config.log_formatter</code> defines the formatter of the Rails logger. This option defaults to an instance of <code>ActiveSupport::Logger::SimpleFormatter</code> for all modes except production, where it defaults to <code>Logger::Formatter</code>.</p></li>
287
- <li><p><code>config.log_level</code> defines the verbosity of the Rails logger. This option defaults to <code>:debug</code> for all modes except production, where it defaults to <code>:info</code>.</p></li>
288
- <li><p><code>config.log_tags</code> accepts a list of methods that the <code>request</code> object responds to. This makes it easy to tag log lines with debug information like subdomain and request id - both very helpful in debugging multi-user production applications.</p></li>
289
- <li><p><code>config.logger</code> accepts a logger conforming to the interface of Log4r or the default Ruby <code>Logger</code> class. Defaults to an instance of <code>ActiveSupport::Logger</code>, with auto flushing off in production mode.</p></li>
290
- <li><p><code>config.middleware</code> allows you to configure the application's middleware. This is covered in depth in the <a href="#configuring-middleware">Configuring Middleware</a> section below.</p></li>
291
- <li><p><code>config.reload_classes_only_on_change</code> enables or disables reloading of classes only when tracked files change. By default tracks everything on autoload paths and is set to true. If <code>config.cache_classes</code> is true, this option is ignored.</p></li>
292
- <li><p><code>secrets.secret_key_base</code> is used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get <code>secrets.secret_key_base</code> initialized to a random key present in <code>config/secrets.yml</code>.</p></li>
293
- <li><p><code>config.serve_static_assets</code> 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.</p></li>
294
- <li>
295
- <p><code>config.session_store</code> is usually set up in <code>config/initializers/session_store.rb</code> and specifies what class to use to store the session. Possible values are <code>:cookie_store</code> which is the default, <code>:mem_cache_store</code>, and <code>:disabled</code>. The last one tells Rails not to deal with sessions. Custom session stores can also be specified:</p>
296
- <div class="code_container">
297
- <pre class="brush: ruby; gutter: false; toolbar: false">
298
- config.session_store :my_custom_store
299
-
300
- </pre>
301
- </div>
302
- <p>This custom store must be defined as <code>ActionDispatch::Session::MyCustomStore</code>.</p>
303
- </li>
304
- <li><p><code>config.time_zone</code> sets the default time zone for the application and enables time zone awareness for Active Record.</p></li>
305
- </ul>
306
- <h4 id="configuring-assets">3.2 Configuring Assets</h4>
307
- <ul>
308
- <li><p><code>config.assets.enabled</code> a flag that controls whether the asset
309
- pipeline is enabled. It is set to true by default.</p></li>
310
- <li><p><code>config.assets.raise_runtime_errors</code>* Set this flag to <code>true</code> to enable additional runtime error checking. Recommended in <code>config/environments/development.rb</code> to minimize unexpected behavior when deploying to <code>production</code>.</p></li>
311
- <li><p><code>config.assets.compress</code> a flag that enables the compression of compiled assets. It is explicitly set to true in <code>config/environments/production.rb</code>.</p></li>
312
- <li><p><code>config.assets.css_compressor</code> defines the CSS compressor to use. It is set by default by <code>sass-rails</code>. The unique alternative value at the moment is <code>:yui</code>, which uses the <code>yui-compressor</code> gem.</p></li>
313
- <li><p><code>config.assets.js_compressor</code> defines the JavaScript compressor to use. Possible values are <code>:closure</code>, <code>:uglifier</code> and <code>:yui</code> which require the use of the <code>closure-compiler</code>, <code>uglifier</code> or <code>yui-compressor</code> gems respectively.</p></li>
314
- <li><p><code>config.assets.paths</code> 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.</p></li>
315
- <li><p><code>config.assets.precompile</code> allows you to specify additional assets (other than <code>application.css</code> and <code>application.js</code>) which are to be precompiled when <code>rake assets:precompile</code> is run.</p></li>
316
- <li><p><code>config.assets.prefix</code> defines the prefix where assets are served from. Defaults to <code>/assets</code>.</p></li>
317
- <li><p><code>config.assets.manifest</code> defines the full path to be used for the asset precompiler's manifest file. Defaults to a file named <code>manifest-&lt;random&gt;.json</code> in the <code>config.assets.prefix</code> directory within the public folder.</p></li>
318
- <li><p><code>config.assets.digest</code> enables the use of MD5 fingerprints in asset names. Set to <code>true</code> by default in <code>production.rb</code>.</p></li>
319
- <li><p><code>config.assets.debug</code> disables the concatenation and compression of assets. Set to <code>true</code> by default in <code>development.rb</code>.</p></li>
320
- <li><p><code>config.assets.cache_store</code> defines the cache store that Sprockets will use. The default is the Rails file store.</p></li>
321
- <li><p><code>config.assets.version</code> is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.</p></li>
322
- <li><p><code>config.assets.compile</code> is a boolean that can be used to turn on live Sprockets compilation in production.</p></li>
323
- <li><p><code>config.assets.logger</code> accepts a logger conforming to the interface of Log4r or the default Ruby <code>Logger</code> class. Defaults to the same configured at <code>config.logger</code>. Setting <code>config.assets.logger</code> to false will turn off served assets logging.</p></li>
324
- </ul>
325
- <h4 id="configuring-generators">3.3 Configuring Generators</h4><p>Rails allows you to alter what generators are used with the <code>config.generators</code> method. This method takes a block:</p><div class="code_container">
326
- <pre class="brush: ruby; gutter: false; toolbar: false">
327
- config.generators do |g|
328
- g.orm :active_record
329
- g.test_framework :test_unit
330
- end
331
-
332
- </pre>
333
- </div>
334
- <p>The full set of methods that can be used in this block are as follows:</p>
335
- <ul>
336
- <li>
337
- <code>assets</code> allows to create assets on generating a scaffold. Defaults to <code>true</code>.</li>
338
- <li>
339
- <code>force_plural</code> allows pluralized model names. Defaults to <code>false</code>.</li>
340
- <li>
341
- <code>helper</code> defines whether or not to generate helpers. Defaults to <code>true</code>.</li>
342
- <li>
343
- <code>integration_tool</code> defines which integration tool to use. Defaults to <code>nil</code>.</li>
344
- <li>
345
- <code>javascripts</code> turns on the hook for JavaScript files in generators. Used in Rails for when the <code>scaffold</code> generator is run. Defaults to <code>true</code>.</li>
346
- <li>
347
- <code>javascript_engine</code> configures the engine to be used (for eg. coffee) when generating assets. Defaults to <code>nil</code>.</li>
348
- <li>
349
- <code>orm</code> defines which orm to use. Defaults to <code>false</code> and will use Active Record by default.</li>
350
- <li>
351
- <code>resource_controller</code> defines which generator to use for generating a controller when using <code>rails generate resource</code>. Defaults to <code>:controller</code>.</li>
352
- <li>
353
- <code>scaffold_controller</code> different from <code>resource_controller</code>, defines which generator to use for generating a <em>scaffolded</em> controller when using <code>rails generate scaffold</code>. Defaults to <code>:scaffold_controller</code>.</li>
354
- <li>
355
- <code>stylesheets</code> turns on the hook for stylesheets in generators. Used in Rails for when the <code>scaffold</code> generator is run, but this hook can be used in other generates as well. Defaults to <code>true</code>.</li>
356
- <li>
357
- <code>stylesheet_engine</code> configures the stylesheet engine (for eg. sass) to be used when generating assets. Defaults to <code>:css</code>.</li>
358
- <li>
359
- <code>test_framework</code> defines which test framework to use. Defaults to <code>false</code> and will use Test::Unit by default.</li>
360
- <li>
361
- <code>template_engine</code> defines which template engine to use, such as ERB or Haml. Defaults to <code>:erb</code>.</li>
362
- </ul>
363
- <h4 id="configuring-middleware">3.4 Configuring Middleware</h4><p>Every Rails application comes with a standard set of middleware which it uses in this order in the development environment:</p>
364
- <ul>
365
- <li>
366
- <code>ActionDispatch::SSL</code> forces every request to be under HTTPS protocol. Will be available if <code>config.force_ssl</code> is set to <code>true</code>. Options passed to this can be configured by using <code>config.ssl_options</code>.</li>
367
- <li>
368
- <code>ActionDispatch::Static</code> is used to serve static assets. Disabled if <code>config.serve_static_assets</code> is <code>false</code>.</li>
369
- <li>
370
- <code>Rack::Lock</code> wraps the app in mutex so it can only be called by a single thread at a time. Only enabled when <code>config.cache_classes</code> is <code>false</code>.</li>
371
- <li>
372
- <code>ActiveSupport::Cache::Strategy::LocalCache</code> 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>
373
- <li>
374
- <code>Rack::Runtime</code> sets an <code>X-Runtime</code> header, containing the time (in seconds) taken to execute the request.</li>
375
- <li>
376
- <code>Rails::Rack::Logger</code> notifies the logs that the request has begun. After request is complete, flushes all the logs.</li>
377
- <li>
378
- <code>ActionDispatch::ShowExceptions</code> rescues any exception returned by the application and renders nice exception pages if the request is local or if <code>config.consider_all_requests_local</code> is set to <code>true</code>. If <code>config.action_dispatch.show_exceptions</code> is set to <code>false</code>, exceptions will be raised regardless.</li>
379
- <li>
380
- <code>ActionDispatch::RequestId</code> makes a unique X-Request-Id header available to the response and enables the <code>ActionDispatch::Request#uuid</code> method.</li>
381
- <li>
382
- <code>ActionDispatch::RemoteIp</code> checks for IP spoofing attacks and gets valid <code>client_ip</code> from request headers. Configurable with the <code>config.action_dispatch.ip_spoofing_check</code>, and <code>config.action_dispatch.trusted_proxies</code> options.</li>
383
- <li>
384
- <code>Rack::Sendfile</code> intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with <code>config.action_dispatch.x_sendfile_header</code>.</li>
385
- <li>
386
- <code>ActionDispatch::Callbacks</code> runs the prepare callbacks before serving the request.</li>
387
- <li>
388
- <code>ActiveRecord::ConnectionAdapters::ConnectionManagement</code> cleans active connections after each request, unless the <code>rack.test</code> key in the request environment is set to <code>true</code>.</li>
389
- <li>
390
- <code>ActiveRecord::QueryCache</code> caches all SELECT queries generated in a request. If any INSERT or UPDATE takes place then the cache is cleaned.</li>
391
- <li>
392
- <code>ActionDispatch::Cookies</code> sets cookies for the request.</li>
393
- <li>
394
- <code>ActionDispatch::Session::CookieStore</code> is responsible for storing the session in cookies. An alternate middleware can be used for this by changing the <code>config.action_controller.session_store</code> to an alternate value. Additionally, options passed to this can be configured by using <code>config.action_controller.session_options</code>.</li>
395
- <li>
396
- <code>ActionDispatch::Flash</code> sets up the <code>flash</code> keys. Only available if <code>config.action_controller.session_store</code> is set to a value.</li>
397
- <li>
398
- <code>ActionDispatch::ParamsParser</code> parses out parameters from the request into <code>params</code>.</li>
399
- <li>
400
- <code>Rack::MethodOverride</code> allows the method to be overridden if <code>params[:_method]</code> is set. This is the middleware which supports the PATCH, PUT, and DELETE HTTP method types.</li>
401
- <li>
402
- <code>ActionDispatch::Head</code> converts HEAD requests to GET requests and serves them as so.</li>
403
- </ul>
404
- <p>Besides these usual middleware, you can add your own by using the <code>config.middleware.use</code> method:</p><div class="code_container">
405
- <pre class="brush: ruby; gutter: false; toolbar: false">
406
- config.middleware.use Magical::Unicorns
407
-
408
- </pre>
409
- </div>
410
- <p>This will put the <code>Magical::Unicorns</code> middleware on the end of the stack. You can use <code>insert_before</code> if you wish to add a middleware before another.</p><div class="code_container">
411
- <pre class="brush: ruby; gutter: false; toolbar: false">
412
- config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns
413
-
414
- </pre>
415
- </div>
416
- <p>There's also <code>insert_after</code> which will insert a middleware after another:</p><div class="code_container">
417
- <pre class="brush: ruby; gutter: false; toolbar: false">
418
- config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns
419
-
420
- </pre>
421
- </div>
422
- <p>Middlewares can also be completely swapped out and replaced with others:</p><div class="code_container">
423
- <pre class="brush: ruby; gutter: false; toolbar: false">
424
- config.middleware.swap ActionController::Failsafe, Lifo::Failsafe
425
-
426
- </pre>
427
- </div>
428
- <p>They can also be removed from the stack completely:</p><div class="code_container">
429
- <pre class="brush: ruby; gutter: false; toolbar: false">
430
- config.middleware.delete "Rack::MethodOverride"
431
-
432
- </pre>
433
- </div>
434
- <h4 id="configuring-i18n">3.5 Configuring i18n</h4><p>All these configuration options are delegated to the <code>I18n</code> library.</p>
435
- <ul>
436
- <li><p><code>config.i18n.available_locales</code> whitelists the available locales for the app. Defaults to all locale keys found in locale files, usually only <code>:en</code> on a new application.</p></li>
437
- <li><p><code>config.i18n.default_locale</code> sets the default locale of an application used for i18n. Defaults to <code>:en</code>.</p></li>
438
- <li><p><code>config.i18n.enforce_available_locales</code> ensures that all locales passed through i18n must be declared in the <code>available_locales</code> list, raising an <code>I18n::InvalidLocale</code> exception when setting an unavailable locale. Defaults to <code>true</code>. It is recommended not to disable this option unless strongly required, since this works as a security measure against setting any invalid locale from user input.</p></li>
439
- <li><p><code>config.i18n.load_path</code> sets the path Rails uses to look for locale files. Defaults to <code>config/locales/*.{yml,rb}</code>.</p></li>
440
- </ul>
441
- <h4 id="configuring-active-record">3.6 Configuring Active Record</h4><p><code>config.active_record</code> includes a variety of configuration options:</p>
442
- <ul>
443
- <li><p><code>config.active_record.logger</code> 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 <code>logger</code> on either an Active Record model class or an Active Record model instance. Set to <code>nil</code> to disable logging.</p></li>
444
- <li><p><code>config.active_record.primary_key_prefix_type</code> lets you adjust the naming for primary key columns. By default, Rails assumes that primary key columns are named <code>id</code> (and this configuration option doesn't need to be set.) There are two other choices:
445
- ** <code>:table_name</code> would make the primary key for the Customer class <code>customerid</code>
446
- ** <code>:table_name_with_underscore</code> would make the primary key for the Customer class <code>customer_id</code></p></li>
447
- <li><p><code>config.active_record.table_name_prefix</code> lets you set a global string to be prepended to table names. If you set this to <code>northwest_</code>, then the Customer class will look for <code>northwest_customers</code> as its table. The default is an empty string.</p></li>
448
- <li><p><code>config.active_record.table_name_suffix</code> lets you set a global string to be appended to table names. If you set this to <code>_northwest</code>, then the Customer class will look for <code>customers_northwest</code> as its table. The default is an empty string.</p></li>
449
- <li><p><code>config.active_record.schema_migrations_table_name</code> lets you set a string to be used as the name of the schema migrations table.</p></li>
450
- <li><p><code>config.active_record.pluralize_table_names</code> 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 <code>customers</code> table. If set to false, then the Customer class will use the <code>customer</code> table.</p></li>
451
- <li><p><code>config.active_record.default_timezone</code> determines whether to use <code>Time.local</code> (if set to <code>:local</code>) or <code>Time.utc</code> (if set to <code>:utc</code>) when pulling dates and times from the database. The default is <code>:utc</code>.</p></li>
452
- <li><p><code>config.active_record.schema_format</code> controls the format for dumping the database schema to a file. The options are <code>:ruby</code> (the default) for a database-independent version that depends on migrations, or <code>:sql</code> for a set of (potentially database-dependent) SQL statements.</p></li>
453
- <li><p><code>config.active_record.timestamped_migrations</code> 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.</p></li>
454
- <li><p><code>config.active_record.lock_optimistically</code> controls whether Active Record will use optimistic locking and is true by default.</p></li>
455
- <li><p><code>config.active_record.cache_timestamp_format</code> controls the format of the timestamp value in the cache key. Default is <code>:number</code>.</p></li>
456
- <li><p><code>config.active_record.record_timestamps</code> is a boolean value which controls whether or not timestamping of <code>create</code> and <code>update</code> operations on a model occur. The default value is <code>true</code>.</p></li>
457
- <li><p><code>config.active_record.partial_writes</code> is a boolean value and controls whether or not partial writes are used (i.e. whether updates only set attributes that are dirty). Note that when using partial writes, you should also use optimistic locking <code>config.active_record.lock_optimistically</code> since concurrent updates may write attributes based on a possibly stale read state. The default value is <code>true</code>.</p></li>
458
- <li><p><code>config.active_record.attribute_types_cached_by_default</code> sets the attribute types that <code>ActiveRecord::AttributeMethods</code> will cache by default on reads. The default is <code>[:datetime, :timestamp, :time, :date]</code>.</p></li>
459
- <li><p><code>config.active_record.maintain_test_schema</code> is a boolean value which controls whether Active Record should try to keep your test database schema up-to-date with <code>db/schema.rb</code> (or <code>db/structure.sql</code>) when you run your tests. The default is true.</p></li>
460
- <li><p><code>config.active_record.dump_schema_after_migration</code> is a flag which
461
- controls whether or not schema dump should happen (<code>db/schema.rb</code> or
462
- <code>db/structure.sql</code>) when you run migrations. This is set to false in
463
- <code>config/environments/production.rb</code> which is generated by Rails. The
464
- default value is true if this configuration is not set.</p></li>
465
- </ul>
466
- <p>The MySQL adapter adds one additional configuration option:</p>
467
- <ul>
468
- <li>
469
- <code>ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans</code> controls whether Active Record will consider all <code>tinyint(1)</code> columns in a MySQL database to be booleans and is true by default.</li>
470
- </ul>
471
- <p>The schema dumper adds one additional configuration option:</p>
472
- <ul>
473
- <li>
474
- <code>ActiveRecord::SchemaDumper.ignore_tables</code> accepts an array of tables that should <em>not</em> be included in any generated schema file. This setting is ignored unless <code>config.active_record.schema_format == :ruby</code>.</li>
475
- </ul>
476
- <h4 id="configuring-action-controller">3.7 Configuring Action Controller</h4><p><code>config.action_controller</code> includes a number of configuration settings:</p>
477
- <ul>
478
- <li><p><code>config.action_controller.asset_host</code> sets the host for the assets. Useful when CDNs are used for hosting assets rather than the application server itself.</p></li>
479
- <li><p><code>config.action_controller.perform_caching</code> configures whether the application should perform caching or not. Set to false in development mode, true in production.</p></li>
480
- <li><p><code>config.action_controller.default_static_extension</code> configures the extension used for cached pages. Defaults to <code>.html</code>.</p></li>
481
- <li><p><code>config.action_controller.default_charset</code> specifies the default character set for all renders. The default is "utf-8".</p></li>
482
- <li><p><code>config.action_controller.logger</code> 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 <code>nil</code> to disable logging.</p></li>
483
- <li><p><code>config.action_controller.request_forgery_protection_token</code> sets the token parameter name for RequestForgery. Calling <code>protect_from_forgery</code> sets it to <code>:authenticity_token</code> by default.</p></li>
484
- <li><p><code>config.action_controller.allow_forgery_protection</code> enables or disables CSRF protection. By default this is <code>false</code> in test mode and <code>true</code> in all other modes.</p></li>
485
- <li><p><code>config.action_controller.relative_url_root</code> can be used to tell Rails that you are <a href="configuring.html#deploy-to-a-subdirectory-relative-url-root">deploying to a subdirectory</a>. The default is <code>ENV['RAILS_RELATIVE_URL_ROOT']</code>.</p></li>
486
- <li><p><code>config.action_controller.permit_all_parameters</code> sets all the parameters for mass assignment to be permitted by default. The default value is <code>false</code>.</p></li>
487
- <li><p><code>config.action_controller.action_on_unpermitted_parameters</code> enables logging or raising an exception if parameters that are not explicitly permitted are found. Set to <code>:log</code> or <code>:raise</code> to enable. The default value is <code>:log</code> in development and test environments, and <code>false</code> in all other environments.</p></li>
488
- <li><p><code>config.action_controller.always_permitted_parameters</code> sets a list of whitelisted parameters that are permitted by default. The default values are <code>['controller', 'action']</code>.</p></li>
489
- </ul>
490
- <h4 id="configuring-action-dispatch">3.8 Configuring Action Dispatch</h4>
491
- <ul>
492
- <li><p><code>config.action_dispatch.session_store</code> sets the name of the store for session data. The default is <code>:cookie_store</code>; other valid options include <code>:active_record_store</code>, <code>:mem_cache_store</code> or the name of your own custom class.</p></li>
493
- <li>
494
- <p><code>config.action_dispatch.default_headers</code> is a hash with HTTP headers that are set by default in each response. By default, this is defined as:</p>
495
- <div class="code_container">
496
- <pre class="brush: ruby; gutter: false; toolbar: false">
497
- config.action_dispatch.default_headers = {
498
- 'X-Frame-Options' =&gt; 'SAMEORIGIN',
499
- 'X-XSS-Protection' =&gt; '1; mode=block',
500
- 'X-Content-Type-Options' =&gt; 'nosniff'
501
- }
502
-
503
- </pre>
504
- </div>
505
- </li>
506
- <li><p><code>config.action_dispatch.tld_length</code> sets the TLD (top-level domain) length for the application. Defaults to <code>1</code>.</p></li>
507
- <li><p><code>config.action_dispatch.http_auth_salt</code> sets the HTTP Auth salt value. Defaults
508
- to <code>'http authentication'</code>.</p></li>
509
- <li><p><code>config.action_dispatch.signed_cookie_salt</code> sets the signed cookies salt value.
510
- Defaults to <code>'signed cookie'</code>.</p></li>
511
- <li><p><code>config.action_dispatch.encrypted_cookie_salt</code> sets the encrypted cookies salt
512
- value. Defaults to <code>'encrypted cookie'</code>.</p></li>
513
- <li><p><code>config.action_dispatch.encrypted_signed_cookie_salt</code> sets the signed
514
- encrypted cookies salt value. Defaults to <code>'signed encrypted cookie'</code>.</p></li>
515
- <li><p><code>config.action_dispatch.perform_deep_munge</code> configures whether <code>deep_munge</code>
516
- method should be performed on the parameters. See <a href="security.html#unsafe-query-generation">Security Guide</a>
517
- for more information. It defaults to true.</p></li>
518
- <li><p><code>ActionDispatch::Callbacks.before</code> takes a block of code to run before the request.</p></li>
519
- <li><p><code>ActionDispatch::Callbacks.to_prepare</code> takes a block to run after <code>ActionDispatch::Callbacks.before</code>, but before the request. Runs for every request in <code>development</code> mode, but only once for <code>production</code> or environments with <code>cache_classes</code> set to <code>true</code>.</p></li>
520
- <li><p><code>ActionDispatch::Callbacks.after</code> takes a block of code to run after the request.</p></li>
521
- </ul>
522
- <h4 id="configuring-action-view">3.9 Configuring Action View</h4><p><code>config.action_view</code> includes a small number of configuration settings:</p>
523
- <ul>
524
- <li>
525
- <p><code>config.action_view.field_error_proc</code> provides an HTML generator for displaying errors that come from Active Record. The default is</p>
526
- <div class="code_container">
527
- <pre class="brush: ruby; gutter: false; toolbar: false">
528
- Proc.new do |html_tag, instance|
529
- %Q(&lt;div class="field_with_errors"&gt;#{html_tag}&lt;/div&gt;).html_safe
530
- end
531
-
532
- </pre>
533
- </div>
534
- </li>
535
- <li><p><code>config.action_view.default_form_builder</code> tells Rails which form builder to use by default. The default is <code>ActionView::Helpers::FormBuilder</code>. If you want your form builder class to be loaded after initialization (so it's reloaded on each request in development), you can pass it as a <code>String</code></p></li>
536
- <li><p><code>config.action_view.logger</code> accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then used to log information from Action View. Set to <code>nil</code> to disable logging.</p></li>
537
- <li><p><code>config.action_view.erb_trim_mode</code> gives the trim mode to be used by ERB. It defaults to <code>'-'</code>, which turns on trimming of tail spaces and newline when using <code>&lt;%= -%&gt;</code> or <code>&lt;%= =%&gt;</code>. See the <a href="http://www.kuwata-lab.com/erubis/users-guide.06.html#topics-trimspaces">Erubis documentation</a> for more information.</p></li>
538
- <li><p><code>config.action_view.embed_authenticity_token_in_remote_forms</code> allows you to set the default behavior for <code>authenticity_token</code> in forms with <code>:remote =&gt; true</code>. By default it's set to false, which means that remote forms will not include <code>authenticity_token</code>, which is helpful when you're fragment-caching the form. Remote forms get the authenticity from the <code>meta</code> tag, so embedding is unnecessary unless you support browsers without JavaScript. In such case you can either pass <code>:authenticity_token =&gt; true</code> as a form option or set this config setting to <code>true</code></p></li>
539
- <li>
540
- <p><code>config.action_view.prefix_partial_path_with_controller_namespace</code> determines whether or not partials are looked up from a subdirectory in templates rendered from namespaced controllers. For example, consider a controller named <code>Admin::ArticlesController</code> which renders this template:</p>
541
- <div class="code_container">
542
- <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
543
- &lt;%= render @article %&gt;
544
-
545
- </pre>
546
- </div>
547
- <p>The default setting is <code>true</code>, which uses the partial at <code>/admin/articles/_article.erb</code>. Setting the value to <code>false</code> would render <code>/articles/_article.erb</code>, which is the same behavior as rendering from a non-namespaced controller such as <code>ArticlesController</code>.</p>
548
- </li>
549
- <li><p><code>config.action_view.raise_on_missing_translations</code> determines whether an error should be raised for missing translations</p></li>
550
- </ul>
551
- <h4 id="configuring-action-mailer">3.10 Configuring Action Mailer</h4><p>There are a number of settings available on <code>config.action_mailer</code>:</p>
552
- <ul>
553
- <li><p><code>config.action_mailer.logger</code> 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 <code>nil</code> to disable logging.</p></li>
554
- <li>
555
- <p><code>config.action_mailer.smtp_settings</code> allows detailed configuration for the <code>:smtp</code> delivery method. It accepts a hash of options, which can include any of these options:</p>
556
- <ul>
557
- <li>
558
- <code>:address</code> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.</li>
559
- <li>
560
- <code>:port</code> - On the off chance that your mail server doesn't run on port 25, you can change it.</li>
561
- <li>
562
- <code>:domain</code> - If you need to specify a HELO domain, you can do it here.</li>
563
- <li>
564
- <code>:user_name</code> - If your mail server requires authentication, set the username in this setting.</li>
565
- <li>
566
- <code>:password</code> - If your mail server requires authentication, set the password in this setting.</li>
567
- <li>
568
- <code>:authentication</code> - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of <code>:plain</code>, <code>:login</code>, <code>:cram_md5</code>.</li>
569
- </ul>
570
- </li>
571
- <li>
572
- <p><code>config.action_mailer.sendmail_settings</code> allows detailed configuration for the <code>sendmail</code> delivery method. It accepts a hash of options, which can include any of these options:</p>
573
- <ul>
574
- <li>
575
- <code>:location</code> - The location of the sendmail executable. Defaults to <code>/usr/sbin/sendmail</code>.</li>
576
- <li>
577
- <code>:arguments</code> - The command line arguments. Defaults to <code>-i -t</code>.</li>
578
- </ul>
579
- </li>
580
- <li><p><code>config.action_mailer.raise_delivery_errors</code> specifies whether to raise an error if email delivery cannot be completed. It defaults to true.</p></li>
581
- <li><p><code>config.action_mailer.delivery_method</code> defines the delivery method and defaults to <code>:smtp</code>. See the <a href="http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration">configuration section in the Action Mailer guide</a> for more info.</p></li>
582
- <li><p><code>config.action_mailer.perform_deliveries</code> specifies whether mail will actually be delivered and is true by default. It can be convenient to set it to false for testing.</p></li>
583
- <li>
584
- <p><code>config.action_mailer.default_options</code> configures Action Mailer defaults. Use to set options like <code>from</code> or <code>reply_to</code> for every mailer. These default to:</p>
585
- <div class="code_container">
586
- <pre class="brush: ruby; gutter: false; toolbar: false">
587
- mime_version: "1.0",
588
- charset: "UTF-8",
589
- content_type: "text/plain",
590
- parts_order: ["text/plain", "text/enriched", "text/html"]
591
-
592
- </pre>
593
- </div>
594
- <p>Assign a hash to set additional options:</p>
595
- <div class="code_container">
596
- <pre class="brush: ruby; gutter: false; toolbar: false">
597
- config.action_mailer.default_options = {
598
- from: "noreply@example.com"
599
- }
600
-
601
- </pre>
602
- </div>
603
- </li>
604
- <li>
605
- <p><code>config.action_mailer.observers</code> registers observers which will be notified when mail is delivered.</p>
606
- <div class="code_container">
607
- <pre class="brush: ruby; gutter: false; toolbar: false">
608
- config.action_mailer.observers = ["MailObserver"]
609
-
610
- </pre>
611
- </div>
612
- </li>
613
- <li>
614
- <p><code>config.action_mailer.interceptors</code> registers interceptors which will be called before mail is sent.</p>
615
- <div class="code_container">
616
- <pre class="brush: ruby; gutter: false; toolbar: false">
617
- config.action_mailer.interceptors = ["MailInterceptor"]
618
-
619
- </pre>
620
- </div>
621
- </li>
622
- <li>
623
- <p><code>config.action_mailer.preview_path</code> specifies the location of mailer previews.</p>
624
- <div class="code_container">
625
- <pre class="brush: ruby; gutter: false; toolbar: false">
626
- config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
627
-
628
- </pre>
629
- </div>
630
- </li>
631
- <li>
632
- <p><code>config.action_mailer.show_previews</code> enable or disable mailer previews. By default this is <code>true</code> in development.</p>
633
- <div class="code_container">
634
- <pre class="brush: ruby; gutter: false; toolbar: false">
635
- config.action_mailer.show_previews = false
636
-
637
- </pre>
638
- </div>
639
- </li>
640
- </ul>
641
- <h4 id="configuring-active-support">3.11 Configuring Active Support</h4><p>There are a few configuration options available in Active Support:</p>
642
- <ul>
643
- <li><p><code>config.active_support.bare</code> enables or disables the loading of <code>active_support/all</code> when booting Rails. Defaults to <code>nil</code>, which means <code>active_support/all</code> is loaded.</p></li>
644
- <li><p><code>config.active_support.escape_html_entities_in_json</code> enables or disables the escaping of HTML entities in JSON serialization. Defaults to <code>false</code>.</p></li>
645
- <li><p><code>config.active_support.use_standard_json_time_format</code> enables or disables serializing dates to ISO 8601 format. Defaults to <code>true</code>.</p></li>
646
- <li><p><code>config.active_support.time_precision</code> sets the precision of JSON encoded time values. Defaults to <code>3</code>.</p></li>
647
- <li><p><code>ActiveSupport::Logger.silencer</code> is set to <code>false</code> to disable the ability to silence logging in a block. The default is <code>true</code>.</p></li>
648
- <li><p><code>ActiveSupport::Cache::Store.logger</code> specifies the logger to use within cache store operations.</p></li>
649
- <li><p><code>ActiveSupport::Deprecation.behavior</code> alternative setter to <code>config.active_support.deprecation</code> which configures the behavior of deprecation warnings for Rails.</p></li>
650
- <li><p><code>ActiveSupport::Deprecation.silence</code> takes a block in which all deprecation warnings are silenced.</p></li>
651
- <li><p><code>ActiveSupport::Deprecation.silenced</code> sets whether or not to display deprecation warnings.</p></li>
652
- </ul>
653
- <h4 id="configuring-a-database">3.12 Configuring a Database</h4><p>Just about every Rails application will interact with a database. You can connect to the database by setting an environment variable <code>ENV['DATABASE_URL']</code> or by using a configuration file called <code>config/database.yml</code>.</p><p>Using the <code>config/database.yml</code> file you can specify all the information needed to access your database:</p><div class="code_container">
654
- <pre class="brush: plain; gutter: false; toolbar: false">
655
- development:
656
- adapter: postgresql
657
- database: blog_development
658
- pool: 5
659
-
660
- </pre>
661
- </div>
662
- <p>This will connect to the database named <code>blog_development</code> using the <code>postgresql</code> adapter. This same information can be stored in a URL and provided via an environment variable like this:</p><div class="code_container">
663
- <pre class="brush: ruby; gutter: false; toolbar: false">
664
- &gt; puts ENV['DATABASE_URL']
665
- postgresql://localhost/blog_development?pool=5
666
-
667
- </pre>
668
- </div>
669
- <p>The <code>config/database.yml</code> file contains sections for three different environments in which Rails can run by default:</p>
670
- <ul>
671
- <li>The <code>development</code> environment is used on your development/local computer as you interact manually with the application.</li>
672
- <li>The <code>test</code> environment is used when running automated tests.</li>
673
- <li>The <code>production</code> environment is used when you deploy your application for the world to use.</li>
674
- </ul>
675
- <p>If you wish, you can manually specify a URL inside of your <code>config/database.yml</code></p><div class="code_container">
676
- <pre class="brush: plain; gutter: false; toolbar: false">
677
- development:
678
- url: postgresql://localhost/blog_development?pool=5
679
-
680
- </pre>
681
- </div>
682
- <p>The <code>config/database.yml</code> file can contain ERB tags <code>&lt;%= %&gt;</code>. Anything in the tags will be evaluated as Ruby code. You can use this to pull out data from an environment variable or to perform calculations to generate the needed connection information.</p><div class="info"><p>You don't have to update the database configurations manually. If you look at the options of the application generator, you will see that one of the options is named <code>--database</code>. This option allows you to choose an adapter from a list of the most used relational databases. You can even run the generator repeatedly: <code>cd .. &amp;&amp; rails new blog --database=mysql</code>. When you confirm the overwriting of the <code>config/database.yml</code> file, your application will be configured for MySQL instead of SQLite. Detailed examples of the common database connections are below.</p></div><h4 id="connection-preference">3.13 Connection Preference</h4><p>Since there are two ways to set your connection, via environment variable it is important to understand how the two can interact.</p><p>If you have an empty <code>config/database.yml</code> file but your <code>ENV['DATABASE_URL']</code> is present, then Rails will connect to the database via your environment variable:</p><div class="code_container">
683
- <pre class="brush: plain; gutter: false; toolbar: false">
684
- $ cat config/database.yml
685
-
686
- $ echo $DATABASE_URL
687
- postgresql://localhost/my_database
688
-
689
- </pre>
690
- </div>
691
- <p>If you have a <code>config/database.yml</code> but no <code>ENV['DATABASE_URL']</code> then this file will be used to connect to your database:</p><div class="code_container">
692
- <pre class="brush: plain; gutter: false; toolbar: false">
693
- $ cat config/database.yml
694
- development:
695
- adapter: postgresql
696
- database: my_database
697
- host: localhost
698
-
699
- $ echo $DATABASE_URL
700
-
701
- </pre>
702
- </div>
703
- <p>If you have both <code>config/database.yml</code> and <code>ENV['DATABASE_URL']</code> set then Rails will merge the configuration together. To better understand this we must see some examples.</p><p>When duplicate connection information is provided the environment variable will take precedence:</p><div class="code_container">
704
- <pre class="brush: plain; gutter: false; toolbar: false">
705
- $ cat config/database.yml
706
- development:
707
- adapter: sqlite3
708
- database: NOT_my_database
709
- host: localhost
710
-
711
- $ echo $DATABASE_URL
712
- postgresql://localhost/my_database
713
-
714
- $ bin/rails runner 'puts ActiveRecord::Base.configurations'
715
- {"development"=&gt;{"adapter"=&gt;"postgresql", "host"=&gt;"localhost", "database"=&gt;"my_database"}}
716
-
717
- </pre>
718
- </div>
719
- <p>Here the adapter, host, and database match the information in <code>ENV['DATABASE_URL']</code>.</p><p>If non-duplicate information is provided you will get all unique values, environment variable still takes precedence in cases of any conflicts.</p><div class="code_container">
720
- <pre class="brush: plain; gutter: false; toolbar: false">
721
- $ cat config/database.yml
722
- development:
723
- adapter: sqlite3
724
- pool: 5
725
-
726
- $ echo $DATABASE_URL
727
- postgresql://localhost/my_database
728
-
729
- $ bin/rails runner 'puts ActiveRecord::Base.configurations'
730
- {"development"=&gt;{"adapter"=&gt;"postgresql", "host"=&gt;"localhost", "database"=&gt;"my_database", "pool"=&gt;5}}
731
-
732
- </pre>
733
- </div>
734
- <p>Since pool is not in the <code>ENV['DATABASE_URL']</code> provided connection information its information is merged in. Since <code>adapter</code> is duplicate, the <code>ENV['DATABASE_URL']</code> connection information wins.</p><p>The only way to explicitly not use the connection information in <code>ENV['DATABASE_URL']</code> is to specify an explicit URL connection using the <code>"url"</code> sub key:</p><div class="code_container">
735
- <pre class="brush: plain; gutter: false; toolbar: false">
736
- $ cat config/database.yml
737
- development:
738
- url: sqlite3:NOT_my_database
739
-
740
- $ echo $DATABASE_URL
741
- postgresql://localhost/my_database
742
-
743
- $ bin/rails runner 'puts ActiveRecord::Base.configurations'
744
- {"development"=&gt;{"adapter"=&gt;"sqlite3", "database"=&gt;"NOT_my_database"}}
745
-
746
- </pre>
747
- </div>
748
- <p>Here the connection information in <code>ENV['DATABASE_URL']</code> is ignored, note the different adapter and database name.</p><p>Since it is possible to embed ERB in your <code>config/database.yml</code> it is best practice to explicitly show you are using the <code>ENV['DATABASE_URL']</code> to connect to your database. This is especially useful in production since you should not commit secrets like your database password into your source control (such as Git).</p><div class="code_container">
749
- <pre class="brush: plain; gutter: false; toolbar: false">
750
- $ cat config/database.yml
751
- production:
752
- url: &lt;%= ENV['DATABASE_URL'] %&gt;
753
-
754
- </pre>
755
- </div>
756
- <p>Now the behavior is clear, that we are only using the connection information in <code>ENV['DATABASE_URL']</code>.</p><h5 id="configuring-an-sqlite3-database">3.13.1 Configuring an SQLite3 Database</h5><p>Rails comes with built-in support for <a href="http://www.sqlite.org">SQLite3</a>, which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing. Rails defaults to using an SQLite database when creating a new project, but you can always change it later.</p><p>Here's the section of the default configuration file (<code>config/database.yml</code>) with connection information for the development environment:</p><div class="code_container">
757
- <pre class="brush: plain; gutter: false; toolbar: false">
758
- development:
759
- adapter: sqlite3
760
- database: db/development.sqlite3
761
- pool: 5
762
- timeout: 5000
763
-
764
- </pre>
765
- </div>
766
- <div class="note"><p>Rails uses an SQLite3 database for data storage by default because it is a zero configuration database that just works. Rails also supports MySQL and PostgreSQL "out of the box", and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it.</p></div><h5 id="configuring-a-mysql-database">3.13.2 Configuring a MySQL Database</h5><p>If you choose to use MySQL instead of the shipped SQLite3 database, your <code>config/database.yml</code> will look a little different. Here's the development section:</p><div class="code_container">
767
- <pre class="brush: plain; gutter: false; toolbar: false">
768
- development:
769
- adapter: mysql2
770
- encoding: utf8
771
- database: blog_development
772
- pool: 5
773
- username: root
774
- password:
775
- socket: /tmp/mysql.sock
776
-
777
- </pre>
778
- </div>
779
- <p>If your development computer's MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the <code>development</code> section as appropriate.</p><h5 id="configuring-a-postgresql-database">3.13.3 Configuring a PostgreSQL Database</h5><p>If you choose to use PostgreSQL, your <code>config/database.yml</code> will be customized to use PostgreSQL databases:</p><div class="code_container">
780
- <pre class="brush: plain; gutter: false; toolbar: false">
781
- development:
782
- adapter: postgresql
783
- encoding: unicode
784
- database: blog_development
785
- pool: 5
786
-
787
- </pre>
788
- </div>
789
- <p>Prepared Statements are enabled by default on PostgreSQL. You can be disable prepared statements by setting <code>prepared_statements</code> to <code>false</code>:</p><div class="code_container">
790
- <pre class="brush: plain; gutter: false; toolbar: false">
791
- production:
792
- adapter: postgresql
793
- prepared_statements: false
794
-
795
- </pre>
796
- </div>
797
- <p>If enabled, Active Record will create up to <code>1000</code> prepared statements per database connection by default. To modify this behavior you can set <code>statement_limit</code> to a different value:</p><div class="code_container">
798
- <pre class="brush: plain; gutter: false; toolbar: false">
799
- production:
800
- adapter: postgresql
801
- statement_limit: 200
802
-
803
- </pre>
804
- </div>
805
- <p>The more prepared statements in use: the more memory your database will require. If your PostgreSQL database is hitting memory limits, try lowering <code>statement_limit</code> or disabling prepared statements.</p><h5 id="configuring-an-sqlite3-database-for-jruby-platform">3.13.4 Configuring an SQLite3 Database for JRuby Platform</h5><p>If you choose to use SQLite3 and are using JRuby, your <code>config/database.yml</code> will look a little different. Here's the development section:</p><div class="code_container">
806
- <pre class="brush: plain; gutter: false; toolbar: false">
807
- development:
808
- adapter: jdbcsqlite3
809
- database: db/development.sqlite3
810
-
811
- </pre>
812
- </div>
813
- <h5 id="configuring-a-mysql-database-for-jruby-platform">3.13.5 Configuring a MySQL Database for JRuby Platform</h5><p>If you choose to use MySQL and are using JRuby, your <code>config/database.yml</code> will look a little different. Here's the development section:</p><div class="code_container">
814
- <pre class="brush: plain; gutter: false; toolbar: false">
815
- development:
816
- adapter: jdbcmysql
817
- database: blog_development
818
- username: root
819
- password:
820
-
821
- </pre>
822
- </div>
823
- <h5 id="configuring-a-postgresql-database-for-jruby-platform">3.13.6 Configuring a PostgreSQL Database for JRuby Platform</h5><p>If you choose to use PostgreSQL and are using JRuby, your <code>config/database.yml</code> will look a little different. Here's the development section:</p><div class="code_container">
824
- <pre class="brush: plain; gutter: false; toolbar: false">
825
- development:
826
- adapter: jdbcpostgresql
827
- encoding: unicode
828
- database: blog_development
829
- username: blog
830
- password:
831
-
832
- </pre>
833
- </div>
834
- <p>Change the username and password in the <code>development</code> section as appropriate.</p><h4 id="creating-rails-environments">3.14 Creating Rails Environments</h4><p>By default Rails ships with three environments: "development", "test", and "production". While these are sufficient for most use cases, there are circumstances when you want more environments.</p><p>Imagine you have a server which mirrors the production environment but is only used for testing. Such a server is commonly called a "staging server". To define an environment called "staging" for this server, just create a file called <code>config/environments/staging.rb</code>. Please use the contents of any existing file in <code>config/environments</code> as a starting point and make the necessary changes from there.</p><p>That environment is no different than the default ones, start a server with <code>rails server -e staging</code>, a console with <code>rails console staging</code>, <code>Rails.env.staging?</code> works, etc.</p><h4 id="deploy-to-a-subdirectory-(relative-url-root)">3.15 Deploy to a subdirectory (relative url root)</h4><p>By default Rails expects that your application is running at the root
835
- (eg. <code>/</code>). This section explains how to run your application inside a directory.</p><p>Let's assume we want to deploy our application to "/app1". Rails needs to know
836
- this directory to generate the appropriate routes:</p><div class="code_container">
837
- <pre class="brush: ruby; gutter: false; toolbar: false">
838
- config.relative_url_root = "/app1"
839
-
840
- </pre>
841
- </div>
842
- <p>alternatively you can set the <code>RAILS_RELATIVE_URL_ROOT</code> environment
843
- variable.</p><p>Rails will now prepend "/app1" when generating links.</p><h5 id="using-passenger">3.15.1 Using Passenger</h5><p>Passenger makes it easy to run your application in a subdirectory. You can find the relevant configuration in the <a href="http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri">Passenger manual</a>.</p><h5 id="using-a-reverse-proxy">3.15.2 Using a Reverse Proxy</h5><p>Deploying your application using a reverse proxy has definite advantages over traditional deploys. They allow you to have more control over your server by layering the components required by your application.</p><p>Many modern web servers can be used as a proxy server to balance third-party elements such as caching servers or application servers.</p><p>One such application server you can use is <a href="http://unicorn.bogomips.org/">Unicorn</a> to run behind a reverse proxy.</p><p>In this case, you would need to configure the proxy server (NGINX, Apache, etc) to accept connections from your application server (Unicorn). By default Unicorn will listen for TCP connections on port 8080, but you can change the port or configure it to use sockets instead.</p><p>You can find more information in the <a href="http://unicorn.bogomips.org/README.html">Unicorn readme</a> and understand the <a href="http://unicorn.bogomips.org/PHILOSOPHY.html">philosophy</a> behind it.</p><p>Once you've configured the application server, you must proxy requests to it by configuring your web server appropriately. For example your NGINX config may include:</p><div class="code_container">
844
- <pre class="brush: plain; gutter: false; toolbar: false">
845
- upstream application_server {
846
- server 0.0.0.0:8080
847
- }
848
-
849
- server {
850
- listen 80;
851
- server_name localhost;
852
-
853
- root /root/path/to/your_app/public;
854
-
855
- try_files $uri/index.html $uri.html @app;
856
-
857
- location @app {
858
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
859
- proxy_set_header Host $http_host;
860
- proxy_redirect off;
861
- proxy_pass http://application_server;
862
- }
863
-
864
- # some other configuration
865
- }
866
-
867
- </pre>
868
- </div>
869
- <p>Be sure to read the <a href="http://nginx.org/en/docs/">NGINX documentation</a> for the most up-to-date information.</p><h5 id="considerations-when-deploying-to-a-subdirectory">3.15.3 Considerations when deploying to a subdirectory</h5><p>Deploying to a subdirectory in production has implications on various parts of
870
- Rails.</p>
871
- <ul>
872
- <li>development environment:</li>
873
- <li>testing environment:</li>
874
- <li>serving static assets:</li>
875
- <li>asset pipeline:</li>
876
- </ul>
877
- <h3 id="rails-environment-settings">4 Rails Environment Settings</h3><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>
878
- <ul>
879
- <li><p><code>ENV["RAILS_ENV"]</code> defines the Rails environment (production, development, test, and so on) that Rails will run under.</p></li>
880
- <li><p><code>ENV["RAILS_RELATIVE_URL_ROOT"]</code> is used by the routing code to recognize URLs when you <a href="configuring.html#deploy-to-a-subdirectory-relative-url-root">deploy your application to a subdirectory</a>.</p></li>
881
- <li><p><code>ENV["RAILS_CACHE_ID"]</code> and <code>ENV["RAILS_APP_VERSION"]</code> are used to generate expanded cache keys in Rails' caching code. This allows you to have multiple separate caches from the same application.</p></li>
882
- </ul>
883
- <h3 id="using-initializer-files">5 Using Initializer Files</h3><p>After loading the framework and any gems in your application, Rails turns to loading initializers. An initializer is any Ruby file stored under <code>config/initializers</code> in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and gems are loaded, such as options to configure settings for these parts.</p><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><div class="info"><p>If you have any ordering dependency in your initializers, you can control the load order through naming. Initializer files are loaded in alphabetical order by their path. For example, <code>01_critical.rb</code> will be loaded before <code>02_normal.rb</code>.</p></div><h3 id="initialization-events">6 Initialization events</h3><p>Rails has 5 initialization events which can be hooked into (listed in the order that they are run):</p>
884
- <ul>
885
- <li><p><code>before_configuration</code>: This is run as soon as the application constant inherits from <code>Rails::Application</code>. The <code>config</code> calls are evaluated before this happens.</p></li>
886
- <li><p><code>before_initialize</code>: This is run directly before the initialization process of the application occurs with the <code>:bootstrap_hook</code> initializer near the beginning of the Rails initialization process.</p></li>
887
- <li><p><code>to_prepare</code>: Run after the initializers are run 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 <code>development</code>, but only once (during boot-up) in <code>production</code> and <code>test</code>.</p></li>
888
- <li><p><code>before_eager_load</code>: This is run directly before eager loading occurs, which is the default behavior for the <code>production</code> environment and not for the <code>development</code> environment.</p></li>
889
- <li><p><code>after_initialize</code>: Run directly after the initialization of the application, after the application initializers in <code>config/initializers</code> are run.</p></li>
890
- </ul>
891
- <p>To define an event for these hooks, use the block syntax within a <code>Rails::Application</code>, <code>Rails::Railtie</code> or <code>Rails::Engine</code> subclass:</p><div class="code_container">
892
- <pre class="brush: ruby; gutter: false; toolbar: false">
893
- module YourApp
894
- class Application &lt; Rails::Application
895
- config.before_initialize do
896
- # initialization code goes here
897
- end
898
- end
899
- end
900
-
901
- </pre>
902
- </div>
903
- <p>Alternatively, you can also do it through the <code>config</code> method on the <code>Rails.application</code> object:</p><div class="code_container">
904
- <pre class="brush: ruby; gutter: false; toolbar: false">
905
- Rails.application.config.before_initialize do
906
- # initialization code goes here
907
- end
908
-
909
- </pre>
910
- </div>
911
- <div class="warning"><p>Some parts of your application, notably routing, are not yet set up at the point where the <code>after_initialize</code> block is called.</p></div><h4 id="rails::railtie#initializer">6.1 <code>Rails::Railtie#initializer</code>
912
- </h4><p>Rails has several initializers that run on startup that are all defined by using the <code>initializer</code> method from <code>Rails::Railtie</code>. Here's an example of the <code>set_helpers_path</code> initializer from Action Controller:</p><div class="code_container">
913
- <pre class="brush: ruby; gutter: false; toolbar: false">
914
- initializer "action_controller.set_helpers_path" do |app|
915
- ActionController::Helpers.helpers_path = app.helpers_paths
916
- end
917
-
918
- </pre>
919
- </div>
920
- <p>The <code>initializer</code> 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 <code>:before</code> key in the options hash can be specified to specify which initializer this new initializer must run before, and the <code>:after</code> key will specify which initializer to run this initializer <em>after</em>.</p><p>Initializers defined using the <code>initializer</code> method will be run in the order they are defined in, with the exception of ones that use the <code>:before</code> or <code>:after</code> methods.</p><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 "one" through "four" (defined in that order) and you define "four" to go <em>before</em> "four" but <em>after</em> "three", that just isn't logical and Rails will not be able to determine your initializer order.</p></div><p>The block argument of the <code>initializer</code> method is the instance of the application itself, and so we can access the configuration on it by using the <code>config</code> method as done in the example.</p><p>Because <code>Rails::Application</code> inherits from <code>Rails::Railtie</code> (indirectly), you can use the <code>initializer</code> method in <code>config/application.rb</code> to define initializers for the application.</p><h4 id="initializers">6.2 Initializers</h4><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>
921
- <ul>
922
- <li><p><code>load_environment_hook</code> Serves as a placeholder so that <code>:load_environment_config</code> can be defined to run before it.</p></li>
923
- <li><p><code>load_active_support</code> Requires <code>active_support/dependencies</code> which sets up the basis for Active Support. Optionally requires <code>active_support/all</code> if <code>config.active_support.bare</code> is un-truthful, which is the default.</p></li>
924
- <li><p><code>initialize_logger</code> Initializes the logger (an <code>ActiveSupport::Logger</code> object) for the application and makes it accessible at <code>Rails.logger</code>, provided that no initializer inserted before this point has defined <code>Rails.logger</code>.</p></li>
925
- <li><p><code>initialize_cache</code> If <code>Rails.cache</code> isn't set yet, initializes the cache by referencing the value in <code>config.cache_store</code> and stores the outcome as <code>Rails.cache</code>. If this object responds to the <code>middleware</code> method, its middleware is inserted before <code>Rack::Runtime</code> in the middleware stack.</p></li>
926
- <li><p><code>set_clear_dependencies_hook</code> Provides a hook for <code>active_record.set_dispatch_hooks</code> to use, which will run before this initializer. This initializer - which runs only if <code>cache_classes</code> is set to <code>false</code> - uses <code>ActionDispatch::Callbacks.after</code> 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></li>
927
- <li><p><code>initialize_dependency_mechanism</code> If <code>config.cache_classes</code> is true, configures <code>ActiveSupport::Dependencies.mechanism</code> to <code>require</code> dependencies rather than <code>load</code> them.</p></li>
928
- <li><p><code>bootstrap_hook</code> Runs all configured <code>before_initialize</code> blocks.</p></li>
929
- <li><p><code>i18n.callbacks</code> In the development environment, sets up a <code>to_prepare</code> callback which will call <code>I18n.reload!</code> if any of the locales have changed since the last request. In production mode this callback will only run on the first request.</p></li>
930
- <li><p><code>active_support.deprecation_behavior</code> Sets up deprecation reporting for environments, defaulting to <code>:log</code> for development, <code>:notify</code> for production and <code>:stderr</code> for test. If a value isn't set for <code>config.active_support.deprecation</code> then this initializer will prompt the user to configure this line in the current environment's <code>config/environments</code> file. Can be set to an array of values.</p></li>
931
- <li><p><code>active_support.initialize_time_zone</code> Sets the default time zone for the application based on the <code>config.time_zone</code> setting, which defaults to "UTC".</p></li>
932
- <li><p><code>active_support.initialize_beginning_of_week</code> Sets the default beginning of week for the application based on <code>config.beginning_of_week</code> setting, which defaults to <code>:monday</code>.</p></li>
933
- <li><p><code>action_dispatch.configure</code> Configures the <code>ActionDispatch::Http::URL.tld_length</code> to be set to the value of <code>config.action_dispatch.tld_length</code>.</p></li>
934
- <li><p><code>action_view.set_configs</code> Sets up Action View by using the settings in <code>config.action_view</code> by <code>send</code>'ing the method names as setters to <code>ActionView::Base</code> and passing the values through.</p></li>
935
- <li><p><code>action_controller.logger</code> Sets <code>ActionController::Base.logger</code> - if it's not already set - to <code>Rails.logger</code>.</p></li>
936
- <li><p><code>action_controller.initialize_framework_caches</code> Sets <code>ActionController::Base.cache_store</code> - if it's not already set - to <code>Rails.cache</code>.</p></li>
937
- <li><p><code>action_controller.set_configs</code> Sets up Action Controller by using the settings in <code>config.action_controller</code> by <code>send</code>'ing the method names as setters to <code>ActionController::Base</code> and passing the values through.</p></li>
938
- <li><p><code>action_controller.compile_config_methods</code> Initializes methods for the config settings specified so that they are quicker to access.</p></li>
939
- <li><p><code>active_record.initialize_timezone</code> Sets <code>ActiveRecord::Base.time_zone_aware_attributes</code> to true, as well as setting <code>ActiveRecord::Base.default_timezone</code> to UTC. When attributes are read from the database, they will be converted into the time zone specified by <code>Time.zone</code>.</p></li>
940
- <li><p><code>active_record.logger</code> Sets <code>ActiveRecord::Base.logger</code> - if it's not already set - to <code>Rails.logger</code>.</p></li>
941
- <li><p><code>active_record.set_configs</code> Sets up Active Record by using the settings in <code>config.active_record</code> by <code>send</code>'ing the method names as setters to <code>ActiveRecord::Base</code> and passing the values through.</p></li>
942
- <li><p><code>active_record.initialize_database</code> Loads the database configuration (by default) from <code>config/database.yml</code> and establishes a connection for the current environment.</p></li>
943
- <li><p><code>active_record.log_runtime</code> Includes <code>ActiveRecord::Railties::ControllerRuntime</code> which is responsible for reporting the time taken by Active Record calls for the request back to the logger.</p></li>
944
- <li><p><code>active_record.set_dispatch_hooks</code> Resets all reloadable connections to the database if <code>config.cache_classes</code> is set to <code>false</code>.</p></li>
945
- <li><p><code>action_mailer.logger</code> Sets <code>ActionMailer::Base.logger</code> - if it's not already set - to <code>Rails.logger</code>.</p></li>
946
- <li><p><code>action_mailer.set_configs</code> Sets up Action Mailer by using the settings in <code>config.action_mailer</code> by <code>send</code>'ing the method names as setters to <code>ActionMailer::Base</code> and passing the values through.</p></li>
947
- <li><p><code>action_mailer.compile_config_methods</code> Initializes methods for the config settings specified so that they are quicker to access.</p></li>
948
- <li><p><code>set_load_path</code> This initializer runs before <code>bootstrap_hook</code>. Adds the <code>vendor</code>, <code>lib</code>, all directories of <code>app</code> and any paths specified by <code>config.load_paths</code> to <code>$LOAD_PATH</code>.</p></li>
949
- <li><p><code>set_autoload_paths</code> This initializer runs before <code>bootstrap_hook</code>. Adds all sub-directories of <code>app</code> and paths specified by <code>config.autoload_paths</code> to <code>ActiveSupport::Dependencies.autoload_paths</code>.</p></li>
950
- <li><p><code>add_routing_paths</code> Loads (by default) all <code>config/routes.rb</code> files (in the application and railties, including engines) and sets up the routes for the application.</p></li>
951
- <li><p><code>add_locales</code> Adds the files in <code>config/locales</code> (from the application, railties and engines) to <code>I18n.load_path</code>, making available the translations in these files.</p></li>
952
- <li><p><code>add_view_paths</code> Adds the directory <code>app/views</code> from the application, railties and engines to the lookup path for view files for the application.</p></li>
953
- <li><p><code>load_environment_config</code> Loads the <code>config/environments</code> file for the current environment.</p></li>
954
- <li><p><code>append_asset_paths</code> Finds asset paths for the application and all attached railties and keeps a track of the available directories in <code>config.static_asset_paths</code>.</p></li>
955
- <li><p><code>prepend_helpers_path</code> Adds the directory <code>app/helpers</code> from the application, railties and engines to the lookup path for helpers for the application.</p></li>
956
- <li><p><code>load_config_initializers</code> Loads all Ruby files from <code>config/initializers</code> 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 are loaded.</p></li>
957
- <li><p><code>engines_blank_point</code> 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 run.</p></li>
958
- <li><p><code>add_generator_templates</code> Finds templates for generators at <code>lib/templates</code> for the application, railties and engines and adds these to the <code>config.generators.templates</code> setting, which will make the templates available for all generators to reference.</p></li>
959
- <li><p><code>ensure_autoload_once_paths_as_subset</code> Ensures that the <code>config.autoload_once_paths</code> only contains paths from <code>config.autoload_paths</code>. If it contains extra paths, then an exception will be raised.</p></li>
960
- <li><p><code>add_to_prepare_blocks</code> The block for every <code>config.to_prepare</code> call in the application, a railtie or engine is added to the <code>to_prepare</code> callbacks for Action Dispatch which will be run per request in development, or before the first request in production.</p></li>
961
- <li><p><code>add_builtin_route</code> If the application is running under the development environment then this will append the route for <code>rails/info/properties</code> to the application routes. This route provides the detailed information such as Rails and Ruby version for <code>public/index.html</code> in a default Rails application.</p></li>
962
- <li><p><code>build_middleware_stack</code> Builds the middleware stack for the application, returning an object which has a <code>call</code> method which takes a Rack environment object for the request.</p></li>
963
- <li><p><code>eager_load!</code> If <code>config.eager_load</code> is true, runs the <code>config.before_eager_load</code> hooks and then calls <code>eager_load!</code> which will load all <code>config.eager_load_namespaces</code>.</p></li>
964
- <li><p><code>finisher_hook</code> Provides a hook for after the initialization of process of the application is complete, as well as running all the <code>config.after_initialize</code> blocks for the application, railties and engines.</p></li>
965
- <li><p><code>set_routes_reloader</code> Configures Action Dispatch to reload the routes file using <code>ActionDispatch::Callbacks.to_prepare</code>.</p></li>
966
- <li><p><code>disable_dependency_loading</code> Disables the automatic dependency loading if the <code>config.eager_load</code> is set to true.</p></li>
967
- </ul>
968
- <h3 id="database-pooling">7 Database pooling</h3><p>Active Record database connections are managed by <code>ActiveRecord::ConnectionAdapters::ConnectionPool</code> which ensures that a connection pool synchronizes the amount of thread access to a limited number of database connections. This limit defaults to 5 and can be configured in <code>database.yml</code>.</p><div class="code_container">
969
- <pre class="brush: ruby; gutter: false; toolbar: false">
970
- development:
971
- adapter: sqlite3
972
- database: db/development.sqlite3
973
- pool: 5
974
- timeout: 5000
975
-
976
- </pre>
977
- </div>
978
- <p>Since the connection pooling is handled inside of Active Record by default, all application servers (Thin, mongrel, Unicorn etc.) should behave the same. Initially, the database connection pool is empty and it will create additional connections as the demand for them increases, until it reaches the connection pool limit.</p><p>Any one request will check out a connection the first time it requires access to the database, after which it will check the connection back in, at the end of the request, meaning that the additional connection slot will be available again for the next request in the queue.</p><p>If you try to use more connections than are available, Active Record will block
979
- and wait for a connection from the pool. When it cannot get connection, a timeout
980
- error similar to given below will be thrown.</p><div class="code_container">
981
- <pre class="brush: ruby; gutter: false; toolbar: false">
982
- ActiveRecord::ConnectionTimeoutError - could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it:
983
-
984
- </pre>
985
- </div>
986
- <p>If you get the above error, you might want to increase the size of connection
987
- pool by incrementing the <code>pool</code> option in <code>database.yml</code></p><div class="note"><p>If you are running in a multi-threaded environment, there could be a chance that several threads may be accessing multiple connections simultaneously. So depending on your current request load, you could very well have multiple threads contending for a limited amount of connections.</p></div><h3 id="custom-configuration">8 Custom configuration</h3><p>You can configure your own code through the Rails configuration object with custom configuration. It works like this:</p><div class="code_container">
988
- <pre class="brush: ruby; gutter: false; toolbar: false">
989
- config.x.payment_processing.schedule = :daily
990
- config.x.payment_processing.retries = 3
991
- config.x.super_debugger = true
992
-
993
- </pre>
994
- </div>
995
- <p>These configuration points are then available through the configuration object:</p><div class="code_container">
996
- <pre class="brush: ruby; gutter: false; toolbar: false">
997
- Rails.configuration.x.payment_processing.schedule # =&gt; :daily
998
- Rails.configuration.x.payment_processing.retries # =&gt; 3
999
- Rails.configuration.x.super_debugger # =&gt; true
1000
- Rails.configuration.x.super_debugger.not_set # =&gt; nil
1001
-
1002
- </pre>
1003
- </div>
1004
-
1005
-
1006
- <h3>Feedback</h3>
1007
- <p>
1008
- You're encouraged to help improve the quality of this guide.
1009
- </p>
1010
- <p>
1011
- Please contribute if you see any typos or factual errors.
1012
- 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.
1013
- </p>
1014
- <p>
1015
- You may also find incomplete content, or stuff that is not up to date.
1016
- Please do add any missing documentation for master. Make sure to check
1017
- <a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
1018
- if the issues are already fixed or not on the master branch.
1019
- Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
1020
- for style and conventions.
1021
- </p>
1022
- <p>
1023
- If for whatever reason you spot something to fix but cannot patch it yourself, please
1024
- <a href="https://github.com/rails/rails/issues">open an issue</a>.
1025
- </p>
1026
- <p>And last but not least, any kind of discussion regarding Ruby on Rails
1027
- documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
1028
- </p>
1029
- </div>
1030
- </div>
1031
- </div>
1032
-
1033
- <hr class="hide" />
1034
- <div id="footer">
1035
- <div class="wrapper">
1036
- <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>
1037
- <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
1038
-
1039
- </div>
1040
- </div>
1041
-
1042
- <script type="text/javascript" src="javascripts/jquery.min.js"></script>
1043
- <script type="text/javascript" src="javascripts/responsive-tables.js"></script>
1044
- <script type="text/javascript" src="javascripts/guides.js"></script>
1045
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
1046
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
1047
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
1048
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
1049
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
1050
- <script type="text/javascript">
1051
- SyntaxHighlighter.all();
1052
- $(guidesIndex.bind);
1053
- </script>
1054
- </body>
1055
- </html>