rails 4.1.4 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -18
  3. metadata +51 -304
  4. data/guides/CHANGELOG.md +0 -41
  5. data/guides/Rakefile +0 -77
  6. data/guides/assets/images/akshaysurve.jpg +0 -0
  7. data/guides/assets/images/belongs_to.png +0 -0
  8. data/guides/assets/images/book_icon.gif +0 -0
  9. data/guides/assets/images/bullet.gif +0 -0
  10. data/guides/assets/images/chapters_icon.gif +0 -0
  11. data/guides/assets/images/check_bullet.gif +0 -0
  12. data/guides/assets/images/credits_pic_blank.gif +0 -0
  13. data/guides/assets/images/csrf.png +0 -0
  14. data/guides/assets/images/edge_badge.png +0 -0
  15. data/guides/assets/images/favicon.ico +0 -0
  16. data/guides/assets/images/feature_tile.gif +0 -0
  17. data/guides/assets/images/footer_tile.gif +0 -0
  18. data/guides/assets/images/fxn.png +0 -0
  19. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  20. data/guides/assets/images/getting_started/challenge.png +0 -0
  21. data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
  22. data/guides/assets/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  23. data/guides/assets/images/getting_started/form_with_errors.png +0 -0
  24. data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
  25. data/guides/assets/images/getting_started/new_article.png +0 -0
  26. data/guides/assets/images/getting_started/rails_welcome.png +0 -0
  27. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  28. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  29. data/guides/assets/images/getting_started/show_action_for_articles.png +0 -0
  30. data/guides/assets/images/getting_started/template_is_missing_articles_new.png +0 -0
  31. data/guides/assets/images/getting_started/unknown_action_create_for_articles.png +0 -0
  32. data/guides/assets/images/getting_started/unknown_action_new_for_articles.png +0 -0
  33. data/guides/assets/images/grey_bullet.gif +0 -0
  34. data/guides/assets/images/habtm.png +0 -0
  35. data/guides/assets/images/has_many.png +0 -0
  36. data/guides/assets/images/has_many_through.png +0 -0
  37. data/guides/assets/images/has_one.png +0 -0
  38. data/guides/assets/images/has_one_through.png +0 -0
  39. data/guides/assets/images/header_backdrop.png +0 -0
  40. data/guides/assets/images/header_tile.gif +0 -0
  41. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  42. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  43. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  44. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  45. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  46. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  47. data/guides/assets/images/icons/README +0 -5
  48. data/guides/assets/images/icons/callouts/1.png +0 -0
  49. data/guides/assets/images/icons/callouts/10.png +0 -0
  50. data/guides/assets/images/icons/callouts/11.png +0 -0
  51. data/guides/assets/images/icons/callouts/12.png +0 -0
  52. data/guides/assets/images/icons/callouts/13.png +0 -0
  53. data/guides/assets/images/icons/callouts/14.png +0 -0
  54. data/guides/assets/images/icons/callouts/15.png +0 -0
  55. data/guides/assets/images/icons/callouts/2.png +0 -0
  56. data/guides/assets/images/icons/callouts/3.png +0 -0
  57. data/guides/assets/images/icons/callouts/4.png +0 -0
  58. data/guides/assets/images/icons/callouts/5.png +0 -0
  59. data/guides/assets/images/icons/callouts/6.png +0 -0
  60. data/guides/assets/images/icons/callouts/7.png +0 -0
  61. data/guides/assets/images/icons/callouts/8.png +0 -0
  62. data/guides/assets/images/icons/callouts/9.png +0 -0
  63. data/guides/assets/images/icons/caution.png +0 -0
  64. data/guides/assets/images/icons/example.png +0 -0
  65. data/guides/assets/images/icons/home.png +0 -0
  66. data/guides/assets/images/icons/important.png +0 -0
  67. data/guides/assets/images/icons/next.png +0 -0
  68. data/guides/assets/images/icons/note.png +0 -0
  69. data/guides/assets/images/icons/prev.png +0 -0
  70. data/guides/assets/images/icons/tip.png +0 -0
  71. data/guides/assets/images/icons/up.png +0 -0
  72. data/guides/assets/images/icons/warning.png +0 -0
  73. data/guides/assets/images/nav_arrow.gif +0 -0
  74. data/guides/assets/images/oscardelben.jpg +0 -0
  75. data/guides/assets/images/polymorphic.png +0 -0
  76. data/guides/assets/images/radar.png +0 -0
  77. data/guides/assets/images/rails4_features.png +0 -0
  78. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  79. data/guides/assets/images/rails_guides_logo.gif +0 -0
  80. data/guides/assets/images/rails_logo_remix.gif +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 +0 -53
  90. data/guides/assets/javascripts/jquery.min.js +0 -4
  91. data/guides/assets/javascripts/responsive-tables.js +0 -43
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  102. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  103. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  104. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  105. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  106. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  107. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  108. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  109. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  110. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  111. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  112. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  113. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  114. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  115. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  116. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  117. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +0 -17
  118. data/guides/assets/stylesheets/fixes.css +0 -16
  119. data/guides/assets/stylesheets/kindle.css +0 -11
  120. data/guides/assets/stylesheets/main.css +0 -710
  121. data/guides/assets/stylesheets/print.css +0 -52
  122. data/guides/assets/stylesheets/reset.css +0 -43
  123. data/guides/assets/stylesheets/responsive-tables.css +0 -50
  124. data/guides/assets/stylesheets/style.css +0 -13
  125. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +0 -226
  126. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  127. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  128. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  129. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  130. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  131. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  132. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  133. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  134. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  135. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  136. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  137. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  138. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  139. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  140. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  141. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  142. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  143. data/guides/bug_report_templates/action_controller_gem.rb +0 -47
  144. data/guides/bug_report_templates/action_controller_master.rb +0 -53
  145. data/guides/bug_report_templates/active_record_gem.rb +0 -40
  146. data/guides/bug_report_templates/active_record_master.rb +0 -49
  147. data/guides/code/getting_started/Gemfile +0 -40
  148. data/guides/code/getting_started/Gemfile.lock +0 -125
  149. data/guides/code/getting_started/README.rdoc +0 -28
  150. data/guides/code/getting_started/Rakefile +0 -6
  151. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  152. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  153. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  154. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  155. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  156. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  157. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  158. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  159. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  160. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  161. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  162. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  163. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  164. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  165. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  166. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  167. data/guides/code/getting_started/app/models/comment.rb +0 -3
  168. data/guides/code/getting_started/app/models/post.rb +0 -7
  169. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  170. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  171. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  172. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  173. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  174. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  175. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  176. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  177. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  178. data/guides/code/getting_started/bin/bundle +0 -4
  179. data/guides/code/getting_started/bin/rails +0 -4
  180. data/guides/code/getting_started/bin/rake +0 -4
  181. data/guides/code/getting_started/config/application.rb +0 -18
  182. data/guides/code/getting_started/config/boot.rb +0 -4
  183. data/guides/code/getting_started/config/database.yml +0 -25
  184. data/guides/code/getting_started/config/environment.rb +0 -5
  185. data/guides/code/getting_started/config/environments/development.rb +0 -30
  186. data/guides/code/getting_started/config/environments/production.rb +0 -80
  187. data/guides/code/getting_started/config/environments/test.rb +0 -36
  188. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  189. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  190. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  191. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  192. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  193. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  194. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  195. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  196. data/guides/code/getting_started/config/locales/en.yml +0 -23
  197. data/guides/code/getting_started/config/routes.rb +0 -7
  198. data/guides/code/getting_started/config.ru +0 -4
  199. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  200. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  201. data/guides/code/getting_started/db/schema.rb +0 -33
  202. data/guides/code/getting_started/db/seeds.rb +0 -7
  203. data/guides/code/getting_started/public/404.html +0 -60
  204. data/guides/code/getting_started/public/422.html +0 -60
  205. data/guides/code/getting_started/public/500.html +0 -59
  206. data/guides/code/getting_started/public/favicon.ico +0 -0
  207. data/guides/code/getting_started/public/robots.txt +0 -5
  208. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  209. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  210. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  211. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  212. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  213. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  214. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  215. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  216. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  217. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  218. data/guides/code/getting_started/test/test_helper.rb +0 -12
  219. data/guides/rails_guides/generator.rb +0 -248
  220. data/guides/rails_guides/helpers.rb +0 -53
  221. data/guides/rails_guides/indexer.rb +0 -68
  222. data/guides/rails_guides/kindle.rb +0 -119
  223. data/guides/rails_guides/levenshtein.rb +0 -31
  224. data/guides/rails_guides/markdown/renderer.rb +0 -82
  225. data/guides/rails_guides/markdown.rb +0 -163
  226. data/guides/rails_guides.rb +0 -63
  227. data/guides/source/2_2_release_notes.md +0 -435
  228. data/guides/source/2_3_release_notes.md +0 -621
  229. data/guides/source/3_0_release_notes.md +0 -611
  230. data/guides/source/3_1_release_notes.md +0 -556
  231. data/guides/source/3_2_release_notes.md +0 -565
  232. data/guides/source/4_0_release_notes.md +0 -276
  233. data/guides/source/4_1_release_notes.md +0 -731
  234. data/guides/source/_license.html.erb +0 -2
  235. data/guides/source/_welcome.html.erb +0 -25
  236. data/guides/source/action_controller_overview.md +0 -1175
  237. data/guides/source/action_mailer_basics.md +0 -689
  238. data/guides/source/action_view_overview.md +0 -1610
  239. data/guides/source/active_model_basics.md +0 -200
  240. data/guides/source/active_record_basics.md +0 -373
  241. data/guides/source/active_record_callbacks.md +0 -410
  242. data/guides/source/active_record_querying.md +0 -1773
  243. data/guides/source/active_record_validations.md +0 -1169
  244. data/guides/source/active_support_core_extensions.md +0 -3864
  245. data/guides/source/active_support_instrumentation.md +0 -496
  246. data/guides/source/api_documentation_guidelines.md +0 -315
  247. data/guides/source/asset_pipeline.md +0 -1163
  248. data/guides/source/association_basics.md +0 -2229
  249. data/guides/source/caching_with_rails.md +0 -354
  250. data/guides/source/command_line.md +0 -603
  251. data/guides/source/configuring.md +0 -942
  252. data/guides/source/contributing_to_ruby_on_rails.md +0 -544
  253. data/guides/source/credits.html.erb +0 -80
  254. data/guides/source/debugging_rails_applications.md +0 -707
  255. data/guides/source/development_dependencies_install.md +0 -278
  256. data/guides/source/documents.yaml +0 -193
  257. data/guides/source/engines.md +0 -1391
  258. data/guides/source/form_helpers.md +0 -1001
  259. data/guides/source/generators.md +0 -663
  260. data/guides/source/getting_started.md +0 -1947
  261. data/guides/source/i18n.md +0 -1043
  262. data/guides/source/index.html.erb +0 -27
  263. data/guides/source/initialization.md +0 -657
  264. data/guides/source/kindle/copyright.html.erb +0 -1
  265. data/guides/source/kindle/layout.html.erb +0 -27
  266. data/guides/source/kindle/rails_guides.opf.erb +0 -52
  267. data/guides/source/kindle/toc.html.erb +0 -24
  268. data/guides/source/kindle/toc.ncx.erb +0 -64
  269. data/guides/source/kindle/welcome.html.erb +0 -5
  270. data/guides/source/layout.html.erb +0 -146
  271. data/guides/source/layouts_and_rendering.md +0 -1226
  272. data/guides/source/maintenance_policy.md +0 -56
  273. data/guides/source/migrations.md +0 -1109
  274. data/guides/source/nested_model_forms.md +0 -225
  275. data/guides/source/plugins.md +0 -444
  276. data/guides/source/rails_application_templates.md +0 -248
  277. data/guides/source/rails_on_rack.md +0 -333
  278. data/guides/source/routing.md +0 -1115
  279. data/guides/source/ruby_on_rails_guides_guidelines.md +0 -128
  280. data/guides/source/security.md +0 -1018
  281. data/guides/source/testing.md +0 -1052
  282. data/guides/source/upgrading_ruby_on_rails.md +0 -899
  283. data/guides/source/working_with_javascript_in_rails.md +0 -405
  284. data/guides/w3c_validator.rb +0 -95
@@ -1,27 +0,0 @@
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 %>
@@ -1,657 +0,0 @@
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
- * The timeline of Rails' initialization sequence.
11
- * Where different files are required by the boot sequence.
12
- * How the Rails::Server interface is defined and used.
13
-
14
- --------------------------------------------------------------------------------
15
-
16
- This guide goes through every method call that is
17
- required to boot up the Ruby on Rails stack for a default Rails 4
18
- application, explaining each part in detail along the way. For this
19
- guide, we will be focusing on what happens when you execute `rails server`
20
- to boot your app.
21
-
22
- NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified.
23
-
24
- TIP: If you want to follow along while browsing the Rails [source
25
- code](https://github.com/rails/rails), we recommend that you use the `t`
26
- key binding to open the file finder inside GitHub and find files
27
- quickly.
28
-
29
- Launch!
30
- -------
31
-
32
- Let's start to boot and initialize the app. A Rails application is usually
33
- started by running `rails console` or `rails server`.
34
-
35
- ### `railties/bin/rails`
36
-
37
- The `rails` in the command `rails server` is a ruby executable in your load
38
- path. This executable contains the following lines:
39
-
40
- ```ruby
41
- version = ">= 0"
42
- load Gem.bin_path('railties', 'rails', version)
43
- ```
44
-
45
- If you try out this command in a Rails console, you would see that this loads
46
- `railties/bin/rails`. A part of the file `railties/bin/rails.rb` has the
47
- following code:
48
-
49
- ```ruby
50
- require "rails/cli"
51
- ```
52
-
53
- The file `railties/lib/rails/cli` in turn calls
54
- `Rails::AppRailsLoader.exec_app_rails`.
55
-
56
- ### `railties/lib/rails/app_rails_loader.rb`
57
-
58
- The primary goal of the function `exec_app_rails` is to execute your app's
59
- `bin/rails`. If the current directory does not have a `bin/rails`, it will
60
- navigate upwards until it finds a `bin/rails` executable. Thus one can invoke a
61
- `rails` command from anywhere inside a rails application.
62
-
63
- For `rails server` the equivalent of the following command is executed:
64
-
65
- ```bash
66
- $ exec ruby bin/rails server
67
- ```
68
-
69
- ### `bin/rails`
70
-
71
- This file is as follows:
72
-
73
- ```ruby
74
- #!/usr/bin/env ruby
75
- APP_PATH = File.expand_path('../../config/application', __FILE__)
76
- require_relative '../config/boot'
77
- require 'rails/commands'
78
- ```
79
-
80
- 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.
81
-
82
- ### `config/boot.rb`
83
-
84
- `config/boot.rb` contains:
85
-
86
- ```ruby
87
- # Set up gems listed in the Gemfile.
88
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
89
-
90
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
91
- ```
92
-
93
- In a standard Rails application, there's a `Gemfile` which declares all
94
- dependencies of the application. `config/boot.rb` sets
95
- `ENV['BUNDLE_GEMFILE']` to the location of this file. If the Gemfile
96
- exists, then `bundler/setup` is required. The require is used by Bundler to
97
- configure the load path for your Gemfile's dependencies.
98
-
99
- A standard Rails application depends on several gems, specifically:
100
-
101
- * abstract
102
- * actionmailer
103
- * actionpack
104
- * activemodel
105
- * activerecord
106
- * activesupport
107
- * arel
108
- * builder
109
- * bundler
110
- * erubis
111
- * i18n
112
- * mail
113
- * mime-types
114
- * polyglot
115
- * rack
116
- * rack-cache
117
- * rack-mount
118
- * rack-test
119
- * rails
120
- * railties
121
- * rake
122
- * sqlite3-ruby
123
- * thor
124
- * treetop
125
- * tzinfo
126
-
127
- ### `rails/commands.rb`
128
-
129
- Once `config/boot.rb` has finished, the next file that is required is
130
- `rails/commands`, which helps in expanding aliases. In the current case, the
131
- `ARGV` array simply contains `server` which will be passed over:
132
-
133
- ```ruby
134
- ARGV << '--help' if ARGV.empty?
135
-
136
- aliases = {
137
- "g" => "generate",
138
- "d" => "destroy",
139
- "c" => "console",
140
- "s" => "server",
141
- "db" => "dbconsole",
142
- "r" => "runner"
143
- }
144
-
145
- command = ARGV.shift
146
- command = aliases[command] || command
147
-
148
- require 'rails/commands/commands_tasks'
149
-
150
- Rails::CommandsTasks.new(ARGV).run_command!(command)
151
- ```
152
-
153
- TIP: As you can see, an empty ARGV list will make Rails show the help
154
- snippet.
155
-
156
- If we had used `s` rather than `server`, Rails would have used the `aliases`
157
- defined here to find the matching command.
158
-
159
- ### `rails/commands/command_tasks.rb`
160
-
161
- When one types an incorrect rails command, the `run_command` is responsible for
162
- throwing an error message. If the command is valid, a method of the same name
163
- is called.
164
-
165
- ```ruby
166
- COMMAND_WHITELIST = %(plugin generate destroy console server dbconsole application runner new version help)
167
-
168
- def run_command!(command)
169
- if COMMAND_WHITELIST.include?(command)
170
- send(command)
171
- else
172
- write_error_message(command)
173
- end
174
- end
175
- ```
176
-
177
- With the `server` command, Rails will further run the following code:
178
-
179
- ```ruby
180
- def set_application_directory!
181
- Dir.chdir(File.expand_path('../../', APP_PATH)) unless
182
- File.exist?(File.expand_path("config.ru"))
183
- end
184
-
185
- def server
186
- set_application_directory!
187
- require_command!("server")
188
-
189
- Rails::Server.new.tap do |server|
190
- require APP_PATH
191
- Dir.chdir(Rails.application.root)
192
- server.start
193
- end
194
- end
195
-
196
- def require_command!(command)
197
- require "rails/commands/#{command}"
198
- end
199
- ```
200
-
201
- This file will change into the Rails root directory (a path two directories up
202
- from `APP_PATH` which points at `config/application.rb`), but only if the
203
- `config.ru` file isn't found. This then requires `rails/commands/server` which
204
- sets up the `Rails::Server` class.
205
-
206
- ```ruby
207
- require 'fileutils'
208
- require 'optparse'
209
- require 'action_dispatch'
210
-
211
- module Rails
212
- class Server < ::Rack::Server
213
- ```
214
-
215
- `fileutils` and `optparse` are standard Ruby libraries which provide helper functions for working with files and parsing options.
216
-
217
- ### `actionpack/lib/action_dispatch.rb`
218
-
219
- Action Dispatch is the routing component of the Rails framework.
220
- It adds functionality like routing, session, and common middlewares.
221
-
222
- ### `rails/commands/server.rb`
223
-
224
- The `Rails::Server` class is defined in this file by inheriting from `Rack::Server`. When `Rails::Server.new` is called, this calls the `initialize` method in `rails/commands/server.rb`:
225
-
226
- ```ruby
227
- def initialize(*)
228
- super
229
- set_environment
230
- end
231
- ```
232
-
233
- Firstly, `super` is called which calls the `initialize` method on `Rack::Server`.
234
-
235
- ### Rack: `lib/rack/server.rb`
236
-
237
- `Rack::Server` is responsible for providing a common server interface for all Rack-based applications, which Rails is now a part of.
238
-
239
- The `initialize` method in `Rack::Server` simply sets a couple of variables:
240
-
241
- ```ruby
242
- def initialize(options = nil)
243
- @options = options
244
- @app = options[:app] if options && options[:app]
245
- end
246
- ```
247
-
248
- In this case, `options` will be `nil` so nothing happens in this method.
249
-
250
- 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:
251
-
252
- ```ruby
253
- def set_environment
254
- ENV["RAILS_ENV"] ||= options[:environment]
255
- end
256
- ```
257
-
258
- In fact, the `options` method here does quite a lot. This method is defined in `Rack::Server` like this:
259
-
260
- ```ruby
261
- def options
262
- @options ||= parse_options(ARGV)
263
- end
264
- ```
265
-
266
- Then `parse_options` is defined like this:
267
-
268
- ```ruby
269
- def parse_options(args)
270
- options = default_options
271
-
272
- # Don't evaluate CGI ISINDEX parameters.
273
- # http://www.meb.uni-bonn.de/docs/cgi/cl.html
274
- args.clear if ENV.include?("REQUEST_METHOD")
275
-
276
- options.merge! opt_parser.parse! args
277
- options[:config] = ::File.expand_path(options[:config])
278
- ENV["RACK_ENV"] = options[:environment]
279
- options
280
- end
281
- ```
282
-
283
- With the `default_options` set to this:
284
-
285
- ```ruby
286
- def default_options
287
- {
288
- environment: ENV['RACK_ENV'] || "development",
289
- pid: nil,
290
- Port: 9292,
291
- Host: "0.0.0.0",
292
- AccessLog: [],
293
- config: "config.ru"
294
- }
295
- end
296
- ```
297
-
298
- 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`
299
-
300
- ```ruby
301
- def opt_parser
302
- Options.new
303
- end
304
- ```
305
-
306
- The class **is** defined in `Rack::Server`, but is overwritten in `Rails::Server` to take different arguments. Its `parse!` method begins like this:
307
-
308
- ```ruby
309
- def parse!(args)
310
- args, options = args.dup, {}
311
-
312
- opt_parser = OptionParser.new do |opts|
313
- opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
314
- opts.on("-p", "--port=port", Integer,
315
- "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
316
- ...
317
- ```
318
-
319
- This method will set up keys for the `options` which Rails will then be
320
- able to use to determine how its server should run. After `initialize`
321
- has finished, we jump back into `rails/server` where `APP_PATH` (which was
322
- set earlier) is required.
323
-
324
- ### `config/application`
325
-
326
- When `require APP_PATH` is executed, `config/application.rb` is loaded (recall
327
- that `APP_PATH` is defined in `bin/rails`). This file exists in your application
328
- and it's free for you to change based on your needs.
329
-
330
- ### `Rails::Server#start`
331
-
332
- After `config/application` is loaded, `server.start` is called. This method is
333
- defined like this:
334
-
335
- ```ruby
336
- def start
337
- print_boot_information
338
- trap(:INT) { exit }
339
- create_tmp_directories
340
- log_to_stdout if options[:log_stdout]
341
-
342
- super
343
- ...
344
- end
345
-
346
- private
347
-
348
- def print_boot_information
349
- ...
350
- puts "=> Run `rails server -h` for more startup options"
351
- puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
352
- end
353
-
354
- def create_tmp_directories
355
- %w(cache pids sessions sockets).each do |dir_to_make|
356
- FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make))
357
- end
358
- end
359
-
360
- def log_to_stdout
361
- wrapped_app # touch the app so the logger is set up
362
-
363
- console = ActiveSupport::Logger.new($stdout)
364
- console.formatter = Rails.logger.formatter
365
- console.level = Rails.logger.level
366
-
367
- Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
368
- end
369
- ```
370
-
371
- This is where the first output of the Rails initialization happens. This
372
- method creates a trap for `INT` signals, so if you `CTRL-C` the server,
373
- it will exit the process. As we can see from the code here, it will
374
- create the `tmp/cache`, `tmp/pids`, `tmp/sessions` and `tmp/sockets`
375
- directories. It then calls `wrapped_app` which is responsible for
376
- creating the Rack app, before creating and assigning an
377
- instance of `ActiveSupport::Logger`.
378
-
379
- The `super` method will call `Rack::Server.start` which begins its definition like this:
380
-
381
- ```ruby
382
- def start &blk
383
- if options[:warn]
384
- $-w = true
385
- end
386
-
387
- if includes = options[:include]
388
- $LOAD_PATH.unshift(*includes)
389
- end
390
-
391
- if library = options[:require]
392
- require library
393
- end
394
-
395
- if options[:debug]
396
- $DEBUG = true
397
- require 'pp'
398
- p options[:server]
399
- pp wrapped_app
400
- pp app
401
- end
402
-
403
- check_pid! if options[:pid]
404
-
405
- # Touch the wrapped app, so that the config.ru is loaded before
406
- # daemonization (i.e. before chdir, etc).
407
- wrapped_app
408
-
409
- daemonize_app if options[:daemonize]
410
-
411
- write_pid if options[:pid]
412
-
413
- trap(:INT) do
414
- if server.respond_to?(:shutdown)
415
- server.shutdown
416
- else
417
- exit
418
- end
419
- end
420
-
421
- server.run wrapped_app, options, &blk
422
- end
423
- ```
424
-
425
- The interesting part for a Rails app is the last line, `server.run`. Here we encounter the `wrapped_app` method again, which this time
426
- we're going to explore more (even though it was executed before, and
427
- thus memoized by now).
428
-
429
- ```ruby
430
- @wrapped_app ||= build_app app
431
- ```
432
-
433
- The `app` method here is defined like so:
434
-
435
- ```ruby
436
- def app
437
- @app ||= begin
438
- if !::File.exist? options[:config]
439
- abort "configuration #{options[:config]} not found"
440
- end
441
-
442
- app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
443
- self.options.merge! options
444
- app
445
- end
446
- end
447
- ```
448
-
449
- The `options[:config]` value defaults to `config.ru` which contains this:
450
-
451
- ```ruby
452
- # This file is used by Rack-based servers to start the application.
453
-
454
- require ::File.expand_path('../config/environment', __FILE__)
455
- run <%= app_const %>
456
- ```
457
-
458
-
459
- The `Rack::Builder.parse_file` method here takes the content from this `config.ru` file and parses it using this code:
460
-
461
- ```ruby
462
- app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
463
- TOPLEVEL_BINDING, config
464
- ```
465
-
466
- 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:
467
-
468
- ```ruby
469
- require ::File.expand_path('../config/environment', __FILE__)
470
- ```
471
-
472
- ### `config/environment.rb`
473
-
474
- 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.
475
-
476
- This file begins with requiring `config/application.rb`.
477
-
478
- ### `config/application.rb`
479
-
480
- 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.
481
-
482
- Then the fun begins!
483
-
484
- Loading Rails
485
- -------------
486
-
487
- The next line in `config/application.rb` is:
488
-
489
- ```ruby
490
- require 'rails/all'
491
- ```
492
-
493
- ### `railties/lib/rails/all.rb`
494
-
495
- This file is responsible for requiring all the individual frameworks of Rails:
496
-
497
- ```ruby
498
- require "rails"
499
-
500
- %w(
501
- active_record
502
- action_controller
503
- action_mailer
504
- rails/test_unit
505
- sprockets
506
- ).each do |framework|
507
- begin
508
- require "#{framework}/railtie"
509
- rescue LoadError
510
- end
511
- end
512
- ```
513
-
514
- This is where all the Rails frameworks are loaded and thus made
515
- available to the application. We won't go into detail of what happens
516
- inside each of those frameworks, but you're encouraged to try and
517
- explore them on your own.
518
-
519
- For now, just keep in mind that common functionality like Rails engines,
520
- I18n and Rails configuration are all being defined here.
521
-
522
- ### Back to `config/environment.rb`
523
-
524
- The rest of `config/application.rb` defines the configuration for the
525
- `Rails::Application` which will be used once the application is fully
526
- initialized. When `config/application.rb` has finished loading Rails and defined
527
- the application namespace, we go back to `config/environment.rb`,
528
- where the application is initialized. For example, if the application was called
529
- `Blog`, here we would find `Blog::Application.initialize!`, which is
530
- defined in `rails/application.rb`
531
-
532
- ### `railties/lib/rails/application.rb`
533
-
534
- The `initialize!` method looks like this:
535
-
536
- ```ruby
537
- def initialize!(group=:default) #:nodoc:
538
- raise "Application has been already initialized." if @initialized
539
- run_initializers(group, self)
540
- @initialized = true
541
- self
542
- end
543
- ```
544
-
545
- As you can see, you can only initialize an app once. The initializers are run through
546
- the `run_initializers` method which is defined in `railties/lib/rails/initializable.rb`
547
-
548
- ```ruby
549
- def run_initializers(group=:default, *args)
550
- return if instance_variable_defined?(:@ran)
551
- initializers.tsort_each do |initializer|
552
- initializer.run(*args) if initializer.belongs_to?(group)
553
- end
554
- @ran = true
555
- end
556
- ```
557
-
558
- The run_initializers code itself is tricky. What Rails is doing here is
559
- traversing all the class ancestors looking for those that respond to an
560
- `initializers` method. It then sorts the ancestors by name, and runs them.
561
- For example, the `Engine` class will make all the engines available by
562
- providing an `initializers` method on them.
563
-
564
- The `Rails::Application` class, as defined in `railties/lib/rails/application.rb`
565
- defines `bootstrap`, `railtie`, and `finisher` initializers. The `bootstrap` initializers
566
- prepare the application (like initializing the logger) while the `finisher`
567
- initializers (like building the middleware stack) are run last. The `railtie`
568
- initializers are the initializers which have been defined on the `Rails::Application`
569
- itself and are run between the `bootstrap` and `finishers`.
570
-
571
- After this is done we go back to `Rack::Server`
572
-
573
- ### Rack: lib/rack/server.rb
574
-
575
- Last time we left when the `app` method was being defined:
576
-
577
- ```ruby
578
- def app
579
- @app ||= begin
580
- if !::File.exist? options[:config]
581
- abort "configuration #{options[:config]} not found"
582
- end
583
-
584
- app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
585
- self.options.merge! options
586
- app
587
- end
588
- end
589
- ```
590
-
591
- At this point `app` is the Rails app itself (a middleware), and what
592
- happens next is Rack will call all the provided middlewares:
593
-
594
- ```ruby
595
- def build_app(app)
596
- middleware[options[:environment]].reverse_each do |middleware|
597
- middleware = middleware.call(self) if middleware.respond_to?(:call)
598
- next unless middleware
599
- klass = middleware.shift
600
- app = klass.new(app, *middleware)
601
- end
602
- app
603
- end
604
- ```
605
-
606
- Remember, `build_app` was called (by wrapped_app) in the last line of `Server#start`.
607
- Here's how it looked like when we left:
608
-
609
- ```ruby
610
- server.run wrapped_app, options, &blk
611
- ```
612
-
613
- At this point, the implementation of `server.run` will depend on the
614
- server you're using. For example, if you were using Mongrel, here's what
615
- the `run` method would look like:
616
-
617
- ```ruby
618
- def self.run(app, options={})
619
- server = ::Mongrel::HttpServer.new(
620
- options[:Host] || '0.0.0.0',
621
- options[:Port] || 8080,
622
- options[:num_processors] || 950,
623
- options[:throttle] || 0,
624
- options[:timeout] || 60)
625
- # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
626
- # Use is similar to #run, replacing the app argument with a hash of
627
- # { path=>app, ... } or an instance of Rack::URLMap.
628
- if options[:map]
629
- if app.is_a? Hash
630
- app.each do |path, appl|
631
- path = '/'+path unless path[0] == ?/
632
- server.register(path, Rack::Handler::Mongrel.new(appl))
633
- end
634
- elsif app.is_a? URLMap
635
- app.instance_variable_get(:@mapping).each do |(host, path, appl)|
636
- next if !host.nil? && !options[:Host].nil? && options[:Host] != host
637
- path = '/'+path unless path[0] == ?/
638
- server.register(path, Rack::Handler::Mongrel.new(appl))
639
- end
640
- else
641
- raise ArgumentError, "first argument should be a Hash or URLMap"
642
- end
643
- else
644
- server.register('/', Rack::Handler::Mongrel.new(app))
645
- end
646
- yield server if block_given?
647
- server.run.join
648
- end
649
- ```
650
-
651
- We won't dig into the server configuration itself, but this is
652
- the last piece of our journey in the Rails initialization process.
653
-
654
- This high level overview will help you understand when your code is
655
- executed and how, and overall become a better Rails developer. If you
656
- still want to know more, the Rails source code itself is probably the
657
- best place to go next.
@@ -1 +0,0 @@
1
- <%= render 'license' %>
@@ -1,27 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
-
4
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
- <head>
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
-
8
- <title><%= yield(:page_title) || 'Ruby on Rails Guides' %></title>
9
-
10
- <link rel="stylesheet" type="text/css" href="stylesheets/kindle.css" />
11
-
12
- </head>
13
- <body class="guide">
14
-
15
- <% if content_for? :header_section %>
16
- <%= yield :header_section %>
17
- <div class="pagebreak">
18
- <% end %>
19
-
20
- <% if content_for? :index_section %>
21
- <%= yield :index_section %>
22
- <div class="pagebreak">
23
- <% end %>
24
-
25
- <%= yield.html_safe %>
26
- </body>
27
- </html>