rails 3.2.22.5 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +77 -0
  3. data/guides/CHANGELOG.md +9 -0
  4. data/guides/Rakefile +77 -0
  5. data/guides/assets/images/belongs_to.png +0 -0
  6. data/guides/assets/images/book_icon.gif +0 -0
  7. data/guides/assets/images/bullet.gif +0 -0
  8. data/guides/assets/images/challenge.png +0 -0
  9. data/guides/assets/images/chapters_icon.gif +0 -0
  10. data/guides/assets/images/check_bullet.gif +0 -0
  11. data/guides/assets/images/credits_pic_blank.gif +0 -0
  12. data/guides/assets/images/csrf.png +0 -0
  13. data/guides/assets/images/edge_badge.png +0 -0
  14. data/guides/assets/images/favicon.ico +0 -0
  15. data/guides/assets/images/feature_tile.gif +0 -0
  16. data/guides/assets/images/footer_tile.gif +0 -0
  17. data/guides/assets/images/fxn.png +0 -0
  18. data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
  19. data/guides/assets/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  20. data/guides/assets/images/getting_started/form_with_errors.png +0 -0
  21. data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
  22. data/guides/assets/images/getting_started/new_post.png +0 -0
  23. data/guides/assets/images/getting_started/post_with_comments.png +0 -0
  24. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  25. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  26. data/guides/assets/images/getting_started/show_action_for_posts.png +0 -0
  27. data/guides/assets/images/getting_started/template_is_missing_posts_new.png +0 -0
  28. data/guides/assets/images/getting_started/undefined_method_post_path.png +0 -0
  29. data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
  30. data/guides/assets/images/getting_started/unknown_action_new_for_posts.png +0 -0
  31. data/guides/assets/images/grey_bullet.gif +0 -0
  32. data/guides/assets/images/habtm.png +0 -0
  33. data/guides/assets/images/has_many.png +0 -0
  34. data/guides/assets/images/has_many_through.png +0 -0
  35. data/guides/assets/images/has_one.png +0 -0
  36. data/guides/assets/images/has_one_through.png +0 -0
  37. data/guides/assets/images/header_backdrop.png +0 -0
  38. data/guides/assets/images/header_tile.gif +0 -0
  39. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  40. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  41. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  42. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  43. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  44. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  45. data/guides/assets/images/icons/README +5 -0
  46. data/guides/assets/images/icons/callouts/1.png +0 -0
  47. data/guides/assets/images/icons/callouts/10.png +0 -0
  48. data/guides/assets/images/icons/callouts/11.png +0 -0
  49. data/guides/assets/images/icons/callouts/12.png +0 -0
  50. data/guides/assets/images/icons/callouts/13.png +0 -0
  51. data/guides/assets/images/icons/callouts/14.png +0 -0
  52. data/guides/assets/images/icons/callouts/15.png +0 -0
  53. data/guides/assets/images/icons/callouts/2.png +0 -0
  54. data/guides/assets/images/icons/callouts/3.png +0 -0
  55. data/guides/assets/images/icons/callouts/4.png +0 -0
  56. data/guides/assets/images/icons/callouts/5.png +0 -0
  57. data/guides/assets/images/icons/callouts/6.png +0 -0
  58. data/guides/assets/images/icons/callouts/7.png +0 -0
  59. data/guides/assets/images/icons/callouts/8.png +0 -0
  60. data/guides/assets/images/icons/callouts/9.png +0 -0
  61. data/guides/assets/images/icons/caution.png +0 -0
  62. data/guides/assets/images/icons/example.png +0 -0
  63. data/guides/assets/images/icons/home.png +0 -0
  64. data/guides/assets/images/icons/important.png +0 -0
  65. data/guides/assets/images/icons/next.png +0 -0
  66. data/guides/assets/images/icons/note.png +0 -0
  67. data/guides/assets/images/icons/prev.png +0 -0
  68. data/guides/assets/images/icons/tip.png +0 -0
  69. data/guides/assets/images/icons/up.png +0 -0
  70. data/guides/assets/images/icons/warning.png +0 -0
  71. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  72. data/guides/assets/images/nav_arrow.gif +0 -0
  73. data/guides/assets/images/oscardelben.jpg +0 -0
  74. data/guides/assets/images/polymorphic.png +0 -0
  75. data/guides/assets/images/radar.png +0 -0
  76. data/guides/assets/images/rails4_features.png +0 -0
  77. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  78. data/guides/assets/images/rails_guides_logo.gif +0 -0
  79. data/guides/assets/images/rails_logo_remix.gif +0 -0
  80. data/guides/assets/images/rails_welcome.png +0 -0
  81. data/guides/assets/images/session_fixation.png +0 -0
  82. data/guides/assets/images/tab_grey.gif +0 -0
  83. data/guides/assets/images/tab_info.gif +0 -0
  84. data/guides/assets/images/tab_note.gif +0 -0
  85. data/guides/assets/images/tab_red.gif +0 -0
  86. data/guides/assets/images/tab_yellow.gif +0 -0
  87. data/guides/assets/images/tab_yellow.png +0 -0
  88. data/guides/assets/images/vijaydev.jpg +0 -0
  89. data/guides/assets/javascripts/guides.js +57 -0
  90. data/guides/assets/javascripts/jquery.min.js +4 -0
  91. data/guides/assets/javascripts/responsive-tables.js +43 -0
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
  102. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
  103. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
  104. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
  105. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
  106. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
  107. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
  108. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
  109. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
  110. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
  111. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
  112. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
  113. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
  114. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
  115. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
  116. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
  117. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +17 -0
  118. data/guides/assets/stylesheets/fixes.css +16 -0
  119. data/guides/assets/stylesheets/kindle.css +11 -0
  120. data/guides/assets/stylesheets/main.css +709 -0
  121. data/guides/assets/stylesheets/print.css +52 -0
  122. data/guides/assets/stylesheets/reset.css +43 -0
  123. data/guides/assets/stylesheets/responsive-tables.css +50 -0
  124. data/guides/assets/stylesheets/style.css +13 -0
  125. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +226 -0
  126. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
  127. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
  128. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
  129. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
  130. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  131. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
  132. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
  133. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
  134. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
  135. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
  136. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
  137. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
  138. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  139. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
  140. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
  141. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
  142. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
  143. data/guides/code/getting_started/Gemfile +38 -0
  144. data/guides/code/getting_started/Gemfile.lock +150 -0
  145. data/guides/code/getting_started/README.rdoc +28 -0
  146. data/guides/code/getting_started/Rakefile +6 -0
  147. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
  148. data/guides/code/getting_started/app/assets/javascripts/application.js +16 -0
  149. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
  150. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
  151. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +3 -0
  152. data/guides/code/getting_started/app/assets/stylesheets/application.css +13 -0
  153. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
  154. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
  155. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +3 -0
  156. data/guides/code/getting_started/app/controllers/application_controller.rb +5 -0
  157. data/guides/code/getting_started/app/controllers/comments_controller.rb +17 -0
  158. data/guides/code/getting_started/app/controllers/posts_controller.rb +47 -0
  159. data/guides/code/getting_started/app/controllers/welcome_controller.rb +4 -0
  160. data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
  161. data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
  162. data/guides/code/getting_started/app/helpers/posts_helper.rb +2 -0
  163. data/guides/code/getting_started/app/helpers/welcome_helper.rb +2 -0
  164. data/guides/code/getting_started/app/models/comment.rb +3 -0
  165. data/guides/code/getting_started/app/models/post.rb +7 -0
  166. data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
  167. data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
  168. data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
  169. data/guides/code/getting_started/app/views/posts/_form.html.erb +27 -0
  170. data/guides/code/getting_started/app/views/posts/edit.html.erb +5 -0
  171. data/guides/code/getting_started/app/views/posts/index.html.erb +21 -0
  172. data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
  173. data/guides/code/getting_started/app/views/posts/show.html.erb +18 -0
  174. data/guides/code/getting_started/app/views/welcome/index.html.erb +3 -0
  175. data/guides/code/getting_started/bin/bundle +4 -0
  176. data/guides/code/getting_started/bin/rails +4 -0
  177. data/guides/code/getting_started/bin/rake +4 -0
  178. data/guides/code/getting_started/config.ru +4 -0
  179. data/guides/code/getting_started/config/application.rb +17 -0
  180. data/guides/code/getting_started/config/boot.rb +4 -0
  181. data/guides/code/getting_started/config/database.yml +25 -0
  182. data/guides/code/getting_started/config/environment.rb +5 -0
  183. data/guides/code/getting_started/config/environments/development.rb +30 -0
  184. data/guides/code/getting_started/config/environments/production.rb +80 -0
  185. data/guides/code/getting_started/config/environments/test.rb +36 -0
  186. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
  187. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +4 -0
  188. data/guides/code/getting_started/config/initializers/inflections.rb +16 -0
  189. data/guides/code/getting_started/config/initializers/locale.rb +9 -0
  190. data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
  191. data/guides/code/getting_started/config/initializers/secret_token.rb +12 -0
  192. data/guides/code/getting_started/config/initializers/session_store.rb +3 -0
  193. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
  194. data/guides/code/getting_started/config/locales/en.yml +23 -0
  195. data/guides/code/getting_started/config/routes.rb +7 -0
  196. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +10 -0
  197. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +11 -0
  198. data/guides/code/getting_started/db/schema.rb +33 -0
  199. data/guides/code/getting_started/db/seeds.rb +7 -0
  200. data/guides/code/getting_started/public/404.html +27 -0
  201. data/guides/code/getting_started/public/422.html +26 -0
  202. data/guides/code/getting_started/public/500.html +26 -0
  203. data/guides/code/getting_started/public/favicon.ico +0 -0
  204. data/guides/code/getting_started/public/robots.txt +5 -0
  205. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +7 -0
  206. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +7 -0
  207. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +9 -0
  208. data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
  209. data/guides/code/getting_started/test/fixtures/posts.yml +9 -0
  210. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +4 -0
  211. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +4 -0
  212. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +4 -0
  213. data/guides/code/getting_started/test/models/comment_test.rb +7 -0
  214. data/guides/code/getting_started/test/models/post_test.rb +7 -0
  215. data/guides/code/getting_started/test/test_helper.rb +15 -0
  216. data/guides/rails_guides.rb +44 -0
  217. data/guides/rails_guides/generator.rb +248 -0
  218. data/guides/rails_guides/helpers.rb +51 -0
  219. data/guides/rails_guides/indexer.rb +68 -0
  220. data/guides/rails_guides/kindle.rb +119 -0
  221. data/guides/rails_guides/levenshtein.rb +31 -0
  222. data/guides/rails_guides/markdown.rb +163 -0
  223. data/guides/rails_guides/markdown/renderer.rb +82 -0
  224. data/guides/source/2_2_release_notes.md +435 -0
  225. data/guides/source/2_3_release_notes.md +621 -0
  226. data/guides/source/3_0_release_notes.md +614 -0
  227. data/guides/source/3_1_release_notes.md +556 -0
  228. data/guides/source/3_2_release_notes.md +565 -0
  229. data/guides/source/4_0_release_notes.md +228 -0
  230. data/guides/source/_license.html.erb +2 -0
  231. data/guides/source/_welcome.html.erb +19 -0
  232. data/guides/source/action_controller_overview.md +872 -0
  233. data/guides/source/action_mailer_basics.md +599 -0
  234. data/guides/source/action_view_overview.md +1565 -0
  235. data/guides/source/active_model_basics.md +200 -0
  236. data/guides/source/active_record_basics.md +370 -0
  237. data/guides/source/active_record_callbacks.md +358 -0
  238. data/guides/source/active_record_querying.md +1621 -0
  239. data/guides/source/active_record_validations.md +1128 -0
  240. data/guides/source/active_support_core_extensions.md +3791 -0
  241. data/guides/source/active_support_instrumentation.md +487 -0
  242. data/guides/source/api_documentation_guidelines.md +209 -0
  243. data/guides/source/asset_pipeline.md +832 -0
  244. data/guides/source/association_basics.md +2129 -0
  245. data/guides/source/caching_with_rails.md +350 -0
  246. data/guides/source/command_line.md +594 -0
  247. data/guides/source/configuring.md +736 -0
  248. data/guides/source/contributing_to_ruby_on_rails.md +455 -0
  249. data/guides/source/credits.html.erb +76 -0
  250. data/guides/source/debugging_rails_applications.md +675 -0
  251. data/guides/source/development_dependencies_install.md +195 -0
  252. data/guides/source/documents.yaml +179 -0
  253. data/guides/source/engines.md +961 -0
  254. data/guides/source/form_helpers.md +955 -0
  255. data/guides/source/generators.md +644 -0
  256. data/guides/source/getting_started.md +1775 -0
  257. data/guides/source/i18n.md +983 -0
  258. data/guides/source/index.html.erb +27 -0
  259. data/guides/source/initialization.md +562 -0
  260. data/guides/source/kindle/KINDLE.md +26 -0
  261. data/guides/source/kindle/copyright.html.erb +1 -0
  262. data/guides/source/kindle/layout.html.erb +27 -0
  263. data/guides/source/kindle/rails_guides.opf.erb +52 -0
  264. data/guides/source/kindle/toc.html.erb +24 -0
  265. data/guides/source/kindle/toc.ncx.erb +64 -0
  266. data/guides/source/kindle/welcome.html.erb +5 -0
  267. data/guides/source/layout.html.erb +148 -0
  268. data/guides/source/layouts_and_rendering.md +1132 -0
  269. data/guides/source/migrations.md +1059 -0
  270. data/guides/source/nested_model_forms.md +225 -0
  271. data/guides/source/plugins.md +435 -0
  272. data/guides/source/rails_application_templates.md +229 -0
  273. data/guides/source/rails_on_rack.md +342 -0
  274. data/guides/source/routing.md +1088 -0
  275. data/guides/source/ruby_on_rails_guides_guidelines.md +124 -0
  276. data/guides/source/security.md +973 -0
  277. data/guides/source/testing.md +981 -0
  278. data/guides/source/upgrading_ruby_on_rails.md +286 -0
  279. data/guides/source/working_with_javascript_in_rails.md +396 -0
  280. data/guides/w3c_validator.rb +95 -0
  281. metadata +315 -31
@@ -0,0 +1,27 @@
1
+ <% content_for :page_title do %>
2
+ Ruby on Rails Guides
3
+ <% end %>
4
+
5
+ <% content_for :header_section do %>
6
+ <%= render 'welcome' %>
7
+ <% end %>
8
+
9
+ <% content_for :index_section do %>
10
+ <div id="subCol">
11
+ <dl>
12
+ <dd class="kindle">Rails Guides are also available for <%= link_to 'Kindle', @mobi %>.</dd>
13
+ <dd class="work-in-progress">Guides marked with this icon are currently being worked on and will not be available in the Guides Index menu. While still useful, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections.</dd>
14
+ </dl>
15
+ </div>
16
+ <% end %>
17
+
18
+ <% documents_by_section.each do |section| %>
19
+ <h3><%= section['name'] %></h3>
20
+ <dl>
21
+ <% section['documents'].each do |document| %>
22
+ <%= guide(document['name'], document['url'], :work_in_progress => document['work_in_progress']) do %>
23
+ <p><%= document['description'] %></p>
24
+ <% end %>
25
+ <% end %>
26
+ </dl>
27
+ <% end %>
@@ -0,0 +1,562 @@
1
+ The Rails Initialization Process
2
+ ================================
3
+
4
+ This guide explains the internals of the initialization process in Rails
5
+ as of Rails 4. It is an extremely in-depth guide and recommended for advanced Rails developers.
6
+
7
+ After reading this guide, you will know:
8
+
9
+ * How to use `rails server`.
10
+
11
+ --------------------------------------------------------------------------------
12
+
13
+ This guide goes through every method call that is
14
+ required to boot up the Ruby on Rails stack for a default Rails 4
15
+ application, explaining each part in detail along the way. For this
16
+ guide, we will be focusing on what happens when you execute +rails
17
+ server+ to boot your app.
18
+
19
+ NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified.
20
+
21
+ TIP: If you want to follow along while browsing the Rails [source
22
+ code](https://github.com/rails/rails), we recommend that you use the `t`
23
+ key binding to open the file finder inside GitHub and find files
24
+ quickly.
25
+
26
+ Launch!
27
+ -------
28
+
29
+ Now we finally boot and initialize the app. It all starts with your app's
30
+ `bin/rails` executable. A Rails application is usually started by running
31
+ `rails console` or `rails server`.
32
+
33
+ ### `bin/rails`
34
+
35
+ This file is as follows:
36
+
37
+ ```ruby
38
+ #!/usr/bin/env ruby
39
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
40
+ require File.expand_path('../../config/boot', __FILE__)
41
+ require 'rails/commands'
42
+ ```
43
+
44
+ The `APP_PATH` constant will be used later in `rails/commands`. The `config/boot` file referenced here is the `config/boot.rb` file in our application which is responsible for loading Bundler and setting it up.
45
+
46
+ ### `config/boot.rb`
47
+
48
+ `config/boot.rb` contains:
49
+
50
+ ```ruby
51
+ # Set up gems listed in the Gemfile.
52
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
53
+
54
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
55
+ ```
56
+
57
+ In a standard Rails application, there's a `Gemfile` which declares all
58
+ dependencies of the application. `config/boot.rb` sets
59
+ `ENV['BUNDLE_GEMFILE']` to the location of this file. If the Gemfile
60
+ exists, `bundler/setup` is then required.
61
+
62
+ The gems that a Rails 4 application depends on are as follows:
63
+
64
+ TODO: change these when the Rails 4 release is near.
65
+
66
+ * abstract (1.0.0)
67
+ * actionmailer (4.0.0.beta)
68
+ * actionpack (4.0.0.beta)
69
+ * activemodel (4.0.0.beta)
70
+ * activerecord (4.0.0.beta)
71
+ * activesupport (4.0.0.beta)
72
+ * arel (2.0.7)
73
+ * builder (3.0.0)
74
+ * bundler (1.0.6)
75
+ * erubis (2.6.6)
76
+ * i18n (0.5.0)
77
+ * mail (2.2.12)
78
+ * mime-types (1.16)
79
+ * polyglot (0.3.1)
80
+ * rack (1.2.1)
81
+ * rack-cache (0.5.3)
82
+ * rack-mount (0.6.13)
83
+ * rack-test (0.5.6)
84
+ * rails (4.0.0.beta)
85
+ * railties (4.0.0.beta)
86
+ * rake (0.8.7)
87
+ * sqlite3-ruby (1.3.2)
88
+ * thor (0.14.6)
89
+ * treetop (1.4.9)
90
+ * tzinfo (0.3.23)
91
+
92
+ ### `rails/commands.rb`
93
+
94
+ Once `config/boot.rb` has finished, the next file that is required is `rails/commands` which will execute a command based on the arguments passed in. In this case, the `ARGV` array simply contains `server` which is extracted into the `command` variable using these lines:
95
+
96
+ ```ruby
97
+ ARGV << '--help' if ARGV.empty?
98
+
99
+ aliases = {
100
+ "g" => "generate",
101
+ "d" => "destroy",
102
+ "c" => "console",
103
+ "s" => "server",
104
+ "db" => "dbconsole",
105
+ "r" => "runner"
106
+ }
107
+
108
+ command = ARGV.shift
109
+ command = aliases[command] || command
110
+ ```
111
+
112
+ TIP: As you can see, an empty ARGV list will make Rails show the help
113
+ snippet.
114
+
115
+ If we used `s` rather than `server`, Rails will use the `aliases` defined in the file and match them to their respective commands. With the `server` command, Rails will run this code:
116
+
117
+ ```ruby
118
+ when 'server'
119
+ # Change to the application's path if there is no config.ru file in current dir.
120
+ # This allows us to run `rails server` from other directories, but still get
121
+ # the main config.ru and properly set the tmp directory.
122
+ Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path("config.ru"))
123
+
124
+ require 'rails/commands/server'
125
+ Rails::Server.new.tap do |server|
126
+ # We need to require application after the server sets environment,
127
+ # otherwise the --environment option given to the server won't propagate.
128
+ require APP_PATH
129
+ Dir.chdir(Rails.application.root)
130
+ server.start
131
+ end
132
+ ```
133
+
134
+ This file will change into the root of the directory (a path two directories back from `APP_PATH` which points at `config/application.rb`), but only if the `config.ru` file isn't found. This then requires `rails/commands/server` which sets up the `Rails::Server` class.
135
+
136
+ ```ruby
137
+ require 'fileutils'
138
+ require 'optparse'
139
+ require 'action_dispatch'
140
+
141
+ module Rails
142
+ class Server < ::Rack::Server
143
+ ```
144
+
145
+ `fileutils` and `optparse` are standard Ruby libraries which provide helper functions for working with files and parsing options.
146
+
147
+ ### `actionpack/lib/action_dispatch.rb`
148
+
149
+ Action Dispatch is the routing component of the Rails framework.
150
+ It adds functionalities like routing, session, and common middlewares.
151
+
152
+ ### `rails/commands/server.rb`
153
+
154
+ The `Rails::Server` class is defined in this file as inheriting from `Rack::Server`. When `Rails::Server.new` is called, this calls the `initialize` method in `rails/commands/server.rb`:
155
+
156
+ ```ruby
157
+ def initialize(*)
158
+ super
159
+ set_environment
160
+ end
161
+ ```
162
+
163
+ Firstly, `super` is called which calls the `initialize` method on `Rack::Server`.
164
+
165
+ ### Rack: `lib/rack/server.rb`
166
+
167
+ `Rack::Server` is responsible for providing a common server interface for all Rack-based applications, which Rails is now a part of.
168
+
169
+ The `initialize` method in `Rack::Server` simply sets a couple of variables:
170
+
171
+ ```ruby
172
+ def initialize(options = nil)
173
+ @options = options
174
+ @app = options[:app] if options && options[:app]
175
+ end
176
+ ```
177
+
178
+ In this case, `options` will be `nil` so nothing happens in this method.
179
+
180
+ After `super` has finished in `Rack::Server`, we jump back to `rails/commands/server.rb`. At this point, `set_environment` is called within the context of the `Rails::Server` object and this method doesn't appear to do much at first glance:
181
+
182
+ ```ruby
183
+ def set_environment
184
+ ENV["RAILS_ENV"] ||= options[:environment]
185
+ end
186
+ ```
187
+
188
+ In fact, the `options` method here does quite a lot. This method is defined in `Rack::Server` like this:
189
+
190
+ ```ruby
191
+ def options
192
+ @options ||= parse_options(ARGV)
193
+ end
194
+ ```
195
+
196
+ Then `parse_options` is defined like this:
197
+
198
+ ```ruby
199
+ def parse_options(args)
200
+ options = default_options
201
+
202
+ # Don't evaluate CGI ISINDEX parameters.
203
+ # http://hoohoo.ncsa.uiuc.edu/cgi/cl.html
204
+ args.clear if ENV.include?("REQUEST_METHOD")
205
+
206
+ options.merge! opt_parser.parse! args
207
+ options[:config] = ::File.expand_path(options[:config])
208
+ ENV["RACK_ENV"] = options[:environment]
209
+ options
210
+ end
211
+ ```
212
+
213
+ With the `default_options` set to this:
214
+
215
+ ```ruby
216
+ def default_options
217
+ {
218
+ :environment => ENV['RACK_ENV'] || "development",
219
+ :pid => nil,
220
+ :Port => 9292,
221
+ :Host => "0.0.0.0",
222
+ :AccessLog => [],
223
+ :config => "config.ru"
224
+ }
225
+ end
226
+ ```
227
+
228
+ There is no `REQUEST_METHOD` key in `ENV` so we can skip over that line. The next line merges in the options from `opt_parser` which is defined plainly in `Rack::Server`
229
+
230
+ ```ruby
231
+ def opt_parser
232
+ Options.new
233
+ end
234
+ ```
235
+
236
+ The class **is** defined in `Rack::Server`, but is overwritten in `Rails::Server` to take different arguments. Its `parse!` method begins like this:
237
+
238
+ ```ruby
239
+ def parse!(args)
240
+ args, options = args.dup, {}
241
+
242
+ opt_parser = OptionParser.new do |opts|
243
+ opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
244
+ opts.on("-p", "--port=port", Integer,
245
+ "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
246
+ ...
247
+ ```
248
+
249
+ This method will set up keys for the `options` which Rails will then be
250
+ able to use to determine how its server should run. After `initialize`
251
+ has finished, we jump back into `rails/server` where `APP_PATH` (which was
252
+ set earlier) is required.
253
+
254
+ ### `config/application`
255
+
256
+ When `require APP_PATH` is executed, `config/application.rb` is loaded.
257
+ This file exists in your app and it's free for you to change based
258
+ on your needs.
259
+
260
+ ### `Rails::Server#start`
261
+
262
+ After `config/application` is loaded, `server.start` is called. This method is defined like this:
263
+
264
+ ```ruby
265
+ def start
266
+ url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
267
+ puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
268
+ puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
269
+ puts "=> Call with -d to detach" unless options[:daemonize]
270
+ trap(:INT) { exit }
271
+ puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
272
+
273
+ #Create required tmp directories if not found
274
+ %w(cache pids sessions sockets).each do |dir_to_make|
275
+ FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make))
276
+ end
277
+
278
+ unless options[:daemonize]
279
+ wrapped_app # touch the app so the logger is set up
280
+
281
+ console = ActiveSupport::Logger.new($stdout)
282
+ console.formatter = Rails.logger.formatter
283
+
284
+ Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
285
+ end
286
+
287
+ super
288
+ ensure
289
+ # The '-h' option calls exit before @options is set.
290
+ # If we call 'options' with it unset, we get double help banners.
291
+ puts 'Exiting' unless @options && options[:daemonize]
292
+ end
293
+ ```
294
+
295
+ This is where the first output of the Rails initialization happens. This
296
+ method creates a trap for `INT` signals, so if you `CTRL-C` the server,
297
+ it will exit the process. As we can see from the code here, it will
298
+ create the `tmp/cache`, `tmp/pids`, `tmp/sessions` and `tmp/sockets`
299
+ directories. It then calls `wrapped_app` which is responsible for
300
+ creating the Rack app, before creating and assigning an
301
+ instance of `ActiveSupport::Logger`.
302
+
303
+ The `super` method will call `Rack::Server.start` which begins its definition like this:
304
+
305
+ ```ruby
306
+ def start &blk
307
+ if options[:warn]
308
+ $-w = true
309
+ end
310
+
311
+ if includes = options[:include]
312
+ $LOAD_PATH.unshift(*includes)
313
+ end
314
+
315
+ if library = options[:require]
316
+ require library
317
+ end
318
+
319
+ if options[:debug]
320
+ $DEBUG = true
321
+ require 'pp'
322
+ p options[:server]
323
+ pp wrapped_app
324
+ pp app
325
+ end
326
+
327
+ check_pid! if options[:pid]
328
+
329
+ # Touch the wrapped app, so that the config.ru is loaded before
330
+ # daemonization (i.e. before chdir, etc).
331
+ wrapped_app
332
+
333
+ daemonize_app if options[:daemonize]
334
+
335
+ write_pid if options[:pid]
336
+
337
+ trap(:INT) do
338
+ if server.respond_to?(:shutdown)
339
+ server.shutdown
340
+ else
341
+ exit
342
+ end
343
+ end
344
+
345
+ server.run wrapped_app, options, &blk
346
+ end
347
+ ```
348
+
349
+ The interesting part for a Rails app is the last line, `server.run`. Here we encounter the `wrapped_app` method again, which this time
350
+ we're going to explore more (even though it was executed before, and
351
+ thus memorized by now).
352
+
353
+ ```ruby
354
+ @wrapped_app ||= build_app app
355
+ ```
356
+
357
+ The `app` method here is defined like so:
358
+
359
+ ```ruby
360
+ def app
361
+ @app ||= begin
362
+ if !::File.exist? options[:config]
363
+ abort "configuration #{options[:config]} not found"
364
+ end
365
+
366
+ app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
367
+ self.options.merge! options
368
+ app
369
+ end
370
+ end
371
+ ```
372
+
373
+ The `options[:config]` value defaults to `config.ru` which contains this:
374
+
375
+ ```ruby
376
+ # This file is used by Rack-based servers to start the application.
377
+
378
+ require ::File.expand_path('../config/environment', __FILE__)
379
+ run <%= app_const %>
380
+ ```
381
+
382
+
383
+ The `Rack::Builder.parse_file` method here takes the content from this `config.ru` file and parses it using this code:
384
+
385
+ ```ruby
386
+ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
387
+ TOPLEVEL_BINDING, config
388
+ ```
389
+
390
+ The `initialize` method of `Rack::Builder` will take the block here and execute it within an instance of `Rack::Builder`. This is where the majority of the initialization process of Rails happens. The `require` line for `config/environment.rb` in `config.ru` is the first to run:
391
+
392
+ ```ruby
393
+ require ::File.expand_path('../config/environment', __FILE__)
394
+ ```
395
+
396
+ ### `config/environment.rb`
397
+
398
+ This file is the common file required by `config.ru` (`rails server`) and Passenger. This is where these two ways to run the server meet; everything before this point has been Rack and Rails setup.
399
+
400
+ This file begins with requiring `config/application.rb`.
401
+
402
+ ### `config/application.rb`
403
+
404
+ This file requires `config/boot.rb`, but only if it hasn't been required before, which would be the case in `rails server` but **wouldn't** be the case with Passenger.
405
+
406
+ Then the fun begins!
407
+
408
+ Loading Rails
409
+ -------------
410
+
411
+ The next line in `config/application.rb` is:
412
+
413
+ ```ruby
414
+ require 'rails/all'
415
+ ```
416
+
417
+ ### `railties/lib/rails/all.rb`
418
+
419
+ This file is responsible for requiring all the individual frameworks of Rails:
420
+
421
+ ```ruby
422
+ require "rails"
423
+
424
+ %w(
425
+ active_record
426
+ action_controller
427
+ action_mailer
428
+ rails/test_unit
429
+ sprockets
430
+ ).each do |framework|
431
+ begin
432
+ require "#{framework}/railtie"
433
+ rescue LoadError
434
+ end
435
+ end
436
+ ```
437
+
438
+ This is where all the Rails frameworks are loaded and thus made
439
+ available to the application. We won't go into detail of what happens
440
+ inside each of those frameworks, but you're encouraged to try and
441
+ explore them on your own.
442
+
443
+ For now, just keep in mind that common functionality like Rails engines,
444
+ I18n and Rails configuration is all being defined here.
445
+
446
+ ### Back to `config/environment.rb`
447
+
448
+ When `config/application.rb` has finished loading Rails, and defined
449
+ your application namespace, you go back to `config/environment.rb`,
450
+ where your application is initialized. For example, if you application was called
451
+ `Blog`, here you would find `Blog::Application.initialize!`, which is
452
+ defined in `rails/application.rb`
453
+
454
+ ### `railties/lib/rails/application.rb`
455
+
456
+ The `initialize!` method looks like this:
457
+
458
+ ```ruby
459
+ def initialize!(group=:default) #:nodoc:
460
+ raise "Application has been already initialized." if @initialized
461
+ run_initializers(group, self)
462
+ @initialized = true
463
+ self
464
+ end
465
+ ```
466
+
467
+ As you can see, you can only initialize an app once. This is also where the initializers are run.
468
+
469
+ TODO: review this
470
+
471
+ The initializers code itself is tricky. What Rails is doing here is it
472
+ traverses all the class ancestors looking for an `initializers` method,
473
+ sorting them and running them. For example, the `Engine` class will make
474
+ all the engines available by providing the `initializers` method.
475
+
476
+ After this is done we go back to `Rack::Server`
477
+
478
+ ### Rack: lib/rack/server.rb
479
+
480
+ Last time we left when the `app` method was being defined:
481
+
482
+ ```ruby
483
+ def app
484
+ @app ||= begin
485
+ if !::File.exist? options[:config]
486
+ abort "configuration #{options[:config]} not found"
487
+ end
488
+
489
+ app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
490
+ self.options.merge! options
491
+ app
492
+ end
493
+ end
494
+ ```
495
+
496
+ At this point `app` is the Rails app itself (a middleware), and what
497
+ happens next is Rack will call all the provided middlewares:
498
+
499
+ ```ruby
500
+ def build_app(app)
501
+ middleware[options[:environment]].reverse_each do |middleware|
502
+ middleware = middleware.call(self) if middleware.respond_to?(:call)
503
+ next unless middleware
504
+ klass = middleware.shift
505
+ app = klass.new(app, *middleware)
506
+ end
507
+ app
508
+ end
509
+ ```
510
+
511
+ Remember, `build_app` was called (by wrapped_app) in the last line of `Server#start`.
512
+ Here's how it looked like when we left:
513
+
514
+ ```ruby
515
+ server.run wrapped_app, options, &blk
516
+ ```
517
+
518
+ At this point, the implementation of `server.run` will depend on the
519
+ server you're using. For example, if you were using Mongrel, here's what
520
+ the `run` method would look like:
521
+
522
+ ```ruby
523
+ def self.run(app, options={})
524
+ server = ::Mongrel::HttpServer.new(
525
+ options[:Host] || '0.0.0.0',
526
+ options[:Port] || 8080,
527
+ options[:num_processors] || 950,
528
+ options[:throttle] || 0,
529
+ options[:timeout] || 60)
530
+ # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
531
+ # Use is similar to #run, replacing the app argument with a hash of
532
+ # { path=>app, ... } or an instance of Rack::URLMap.
533
+ if options[:map]
534
+ if app.is_a? Hash
535
+ app.each do |path, appl|
536
+ path = '/'+path unless path[0] == ?/
537
+ server.register(path, Rack::Handler::Mongrel.new(appl))
538
+ end
539
+ elsif app.is_a? URLMap
540
+ app.instance_variable_get(:@mapping).each do |(host, path, appl)|
541
+ next if !host.nil? && !options[:Host].nil? && options[:Host] != host
542
+ path = '/'+path unless path[0] == ?/
543
+ server.register(path, Rack::Handler::Mongrel.new(appl))
544
+ end
545
+ else
546
+ raise ArgumentError, "first argument should be a Hash or URLMap"
547
+ end
548
+ else
549
+ server.register('/', Rack::Handler::Mongrel.new(app))
550
+ end
551
+ yield server if block_given?
552
+ server.run.join
553
+ end
554
+ ```
555
+
556
+ We won't dig into the server configuration itself, but this is
557
+ the last piece of our journey in the Rails initialization process.
558
+
559
+ This high level overview will help you understand when your code is
560
+ executed and how, and overall become a better Rails developer. If you
561
+ still want to know more, the Rails source code itself is probably the
562
+ best place to go next.