railties 3.1.12 → 3.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. data/CHANGELOG.md +2292 -41
  2. data/README.rdoc +14 -5
  3. data/bin/rails +7 -0
  4. data/guides/code/getting_started/Gemfile +27 -0
  5. data/guides/code/getting_started/README.rdoc +261 -0
  6. data/guides/code/getting_started/Rakefile +7 -0
  7. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
  8. data/guides/code/getting_started/app/assets/javascripts/application.js +9 -0
  9. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
  10. data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
  11. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
  12. data/guides/code/getting_started/app/assets/stylesheets/application.css +7 -0
  13. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
  14. data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
  15. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
  16. data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
  17. data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
  18. data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
  19. data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
  20. data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
  21. data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
  22. data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
  23. data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
  24. data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
  25. data/guides/code/getting_started/app/models/comment.rb +3 -0
  26. data/guides/code/getting_started/app/models/post.rb +11 -0
  27. data/guides/code/getting_started/app/models/tag.rb +3 -0
  28. data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
  29. data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
  30. data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
  31. data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
  32. data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
  33. data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
  34. data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
  35. data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
  36. data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
  37. data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
  38. data/guides/code/getting_started/config.ru +4 -0
  39. data/guides/code/getting_started/config/application.rb +53 -0
  40. data/guides/code/getting_started/config/boot.rb +6 -0
  41. data/guides/code/getting_started/config/database.yml +25 -0
  42. data/guides/code/getting_started/config/environment.rb +5 -0
  43. data/guides/code/getting_started/config/environments/development.rb +37 -0
  44. data/guides/code/getting_started/config/environments/production.rb +67 -0
  45. data/guides/code/getting_started/config/environments/test.rb +37 -0
  46. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
  47. data/guides/code/getting_started/config/initializers/inflections.rb +10 -0
  48. data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
  49. data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
  50. data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
  51. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
  52. data/guides/code/getting_started/config/locales/en.yml +5 -0
  53. data/guides/code/getting_started/config/routes.rb +64 -0
  54. data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
  55. data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
  56. data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
  57. data/guides/code/getting_started/db/schema.rb +43 -0
  58. data/guides/code/getting_started/db/seeds.rb +7 -0
  59. data/guides/code/getting_started/doc/README_FOR_APP +2 -0
  60. data/guides/code/getting_started/public/404.html +26 -0
  61. data/guides/code/getting_started/public/422.html +26 -0
  62. data/guides/code/getting_started/public/500.html +26 -0
  63. data/guides/code/getting_started/public/favicon.ico +0 -0
  64. data/guides/code/getting_started/public/robots.txt +5 -0
  65. data/guides/code/getting_started/script/rails +6 -0
  66. data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
  67. data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
  68. data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
  69. data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
  70. data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
  71. data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
  72. data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
  73. data/guides/code/getting_started/test/test_helper.rb +13 -0
  74. data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
  75. data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
  76. data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
  77. data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
  78. data/guides/code/getting_started/test/unit/post_test.rb +7 -0
  79. data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
  80. data/guides/rails_guides/generator.rb +2 -1
  81. data/guides/source/3_0_release_notes.textile +2 -2
  82. data/guides/source/3_1_release_notes.textile +3 -110
  83. data/guides/source/action_controller_overview.textile +11 -13
  84. data/guides/source/action_mailer_basics.textile +7 -18
  85. data/guides/source/action_view_overview.textile +78 -9
  86. data/guides/source/active_model_basics.textile +205 -0
  87. data/guides/source/active_record_basics.textile +31 -31
  88. data/guides/source/active_record_querying.textile +288 -67
  89. data/guides/source/active_record_validations_callbacks.textile +69 -75
  90. data/guides/source/active_resource_basics.textile +48 -2
  91. data/guides/source/active_support_core_extensions.textile +145 -24
  92. data/guides/source/ajax_on_rails.textile +65 -7
  93. data/guides/source/api_documentation_guidelines.textile +0 -6
  94. data/guides/source/asset_pipeline.textile +2 -2
  95. data/guides/source/association_basics.textile +25 -34
  96. data/guides/source/caching_with_rails.textile +12 -17
  97. data/guides/source/command_line.textile +29 -19
  98. data/guides/source/configuring.textile +40 -18
  99. data/guides/source/contributing_to_ruby_on_rails.textile +11 -18
  100. data/guides/source/debugging_rails_applications.textile +10 -21
  101. data/guides/source/engines.textile +618 -0
  102. data/guides/source/form_helpers.textile +1 -12
  103. data/guides/source/generators.textile +9 -11
  104. data/guides/source/getting_started.textile +152 -152
  105. data/guides/source/i18n.textile +4 -5
  106. data/guides/source/index.html.erb +0 -1
  107. data/guides/source/initialization.textile +26 -26
  108. data/guides/source/layouts_and_rendering.textile +97 -61
  109. data/guides/source/migrations.textile +380 -161
  110. data/guides/source/performance_testing.textile +4 -10
  111. data/guides/source/plugins.textile +11 -19
  112. data/guides/source/rails_application_templates.textile +12 -4
  113. data/guides/source/rails_on_rack.textile +25 -19
  114. data/guides/source/routing.textile +6 -13
  115. data/guides/source/ruby_on_rails_guides_guidelines.textile +0 -5
  116. data/guides/source/security.textile +11 -15
  117. data/guides/source/testing.textile +1 -9
  118. data/lib/rails/application.rb +107 -42
  119. data/lib/rails/application/bootstrap.rb +12 -11
  120. data/lib/rails/application/configuration.rb +27 -21
  121. data/lib/rails/application/finisher.rb +40 -17
  122. data/lib/rails/application/route_inspector.rb +75 -0
  123. data/lib/rails/application/routes_reloader.rb +15 -4
  124. data/lib/rails/code_statistics.rb +16 -5
  125. data/lib/rails/commands.rb +6 -5
  126. data/lib/rails/commands/application.rb +8 -1
  127. data/lib/rails/commands/console.rb +2 -0
  128. data/lib/rails/commands/dbconsole.rb +2 -2
  129. data/lib/rails/commands/destroy.rb +0 -2
  130. data/lib/rails/commands/generate.rb +3 -3
  131. data/lib/rails/commands/plugin.rb +161 -159
  132. data/lib/rails/commands/plugin_new.rb +3 -2
  133. data/lib/rails/commands/runner.rb +4 -0
  134. data/lib/rails/console/app.rb +26 -22
  135. data/lib/rails/console/helpers.rb +9 -5
  136. data/lib/rails/engine.rb +70 -34
  137. data/lib/rails/engine/commands.rb +39 -0
  138. data/lib/rails/engine/configuration.rb +1 -1
  139. data/lib/rails/generators.rb +3 -14
  140. data/lib/rails/generators/actions.rb +36 -9
  141. data/lib/rails/generators/app_base.rb +34 -38
  142. data/lib/rails/generators/base.rb +4 -4
  143. data/lib/rails/generators/generated_attribute.rb +1 -1
  144. data/lib/rails/generators/named_base.rb +1 -3
  145. data/lib/rails/generators/rails/app/USAGE +6 -0
  146. data/lib/rails/generators/rails/app/app_generator.rb +6 -2
  147. data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
  148. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +9 -3
  149. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +11 -5
  150. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  151. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  152. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
  153. data/lib/rails/generators/rails/app/templates/config/application.rb +11 -0
  154. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -1
  155. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
  156. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +10 -1
  157. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
  158. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -6
  159. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +5 -0
  160. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  161. data/lib/rails/generators/rails/app/templates/public/500.html +0 -1
  162. data/lib/rails/generators/rails/app/templates/public/index.html +1 -1
  163. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  164. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  165. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  166. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  167. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  168. data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
  169. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  170. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +17 -5
  171. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +1 -0
  172. data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
  173. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  174. data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +1 -1
  175. data/lib/rails/generators/rails/plugin_new/templates/gitignore +4 -3
  176. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +1 -1
  177. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +1 -1
  178. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -3
  179. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
  180. data/lib/rails/generators/rails/task/USAGE +9 -0
  181. data/lib/rails/generators/rails/task/task_generator.rb +12 -0
  182. data/lib/rails/generators/rails/task/templates/task.rb +8 -0
  183. data/lib/rails/generators/resource_helpers.rb +3 -3
  184. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +0 -2
  185. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -4
  186. data/lib/rails/paths.rb +11 -38
  187. data/lib/rails/rack/debugger.rb +3 -4
  188. data/lib/rails/rack/logger.rb +26 -12
  189. data/lib/rails/railtie.rb +6 -1
  190. data/lib/rails/railtie/configuration.rb +12 -5
  191. data/lib/rails/source_annotation_extractor.rb +12 -10
  192. data/lib/rails/tasks/documentation.rake +3 -1
  193. data/lib/rails/tasks/engine.rake +1 -0
  194. data/lib/rails/tasks/misc.rake +1 -1
  195. data/lib/rails/tasks/routes.rake +3 -23
  196. data/lib/rails/test_help.rb +1 -2
  197. data/lib/rails/test_unit/testing.rake +8 -4
  198. data/lib/rails/version.rb +3 -3
  199. metadata +131 -61
  200. checksums.yaml +0 -7
  201. data/lib/rails/generators/rails/plugin/USAGE +0 -13
  202. data/lib/rails/generators/rails/plugin/plugin_generator.rb +0 -54
  203. data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +0 -20
  204. data/lib/rails/generators/rails/plugin/templates/README.tt +0 -13
  205. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +0 -23
  206. data/lib/rails/generators/rails/plugin/templates/init.rb +0 -1
  207. data/lib/rails/generators/rails/plugin/templates/install.rb +0 -1
  208. data/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt +0 -1
  209. data/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -4
  210. data/lib/rails/generators/rails/plugin/templates/uninstall.rb +0 -1
@@ -8,15 +8,15 @@ So, in the process of _internationalizing_ your Rails application you have to:
8
8
 
9
9
  * Ensure you have support for i18n
10
10
  * Tell Rails where to find locale dictionaries
11
- * Tell Rails how to set, preserve and switch locale
11
+ * Tell Rails how to set, preserve and switch locales
12
12
 
13
13
  In the process of _localizing_ your application you'll probably want to do the following three things:
14
14
 
15
- * Replace or supplement Rails' default locale -- e.g. date and time formats, month names, Active Record model names, etc
15
+ * Replace or supplement Rails' default locale -- e.g. date and time formats, month names, Active Record model names, etc.
16
16
  * Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc.
17
17
  * Store the resulting dictionaries somewhere
18
18
 
19
- This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start.
19
+ This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start.
20
20
 
21
21
  endprologue.
22
22
 
@@ -91,7 +91,7 @@ This means, that in the +:en+ locale, the key _hello_ will map to the _Hello wor
91
91
 
92
92
  The I18n library will use *English* as a *default locale*, i.e. if you don't set a different locale, +:en+ will be used for looking up translations.
93
93
 
94
- NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-UK+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it.
94
+ NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-GB+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-GB+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-GB+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it.
95
95
 
96
96
  The *translations load path* (+I18n.load_path+) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you.
97
97
 
@@ -831,7 +831,6 @@ h5. Active Support Methods
831
831
 
832
832
  * +Array#to_sentence+ uses format settings as given in the "support.array":https://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L30 scope.
833
833
 
834
-
835
834
  h3. Customize your I18n Setup
836
835
 
837
836
  h4. Using Different Backends
@@ -30,7 +30,6 @@ Ruby on Rails Guides
30
30
  <% content_for :index_section do %>
31
31
  <div id="subCol">
32
32
  <dl>
33
- <dd class="warning">Rails Guides are a result of the ongoing <a href="http://hackfest.rubyonrails.org">Guides hackfest</a>, and a work in progress.</dd>
34
33
  <dd class="work-in-progress">Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections to the author.</dd>
35
34
  </dl>
36
35
  </div>
@@ -1,6 +1,6 @@
1
1
  h2. The Rails Initialization Process
2
2
 
3
- This guide explains the internals of the initialization process in Rails works as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers.
3
+ This guide explains the internals of the initialization process in Rails as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers.
4
4
 
5
5
  * Using +rails server+
6
6
  * Using Passenger
@@ -17,7 +17,7 @@ As of Rails 3, +script/server+ has become +rails server+. This was done to centr
17
17
 
18
18
  h4. +bin/rails+
19
19
 
20
- The actual +rails+ command is kept in _bin/rails_ at the and goes like this:
20
+ The actual +rails+ command is kept in _bin/rails_:
21
21
 
22
22
  <ruby>
23
23
  #!/usr/bin/env ruby
@@ -31,7 +31,7 @@ rescue LoadError
31
31
  end
32
32
  </ruby>
33
33
 
34
- This file will attempt to load +rails/cli+ and if it cannot find it then add the +railties/lib+ path to the load path (+$:+) and will then try to require it again.
34
+ This file will attempt to load +rails/cli+. If it cannot find it then +railties/lib+ is added to the load path (+$:+) before retrying.
35
35
 
36
36
  h4. +railties/lib/rails/cli.rb+
37
37
 
@@ -56,7 +56,7 @@ else
56
56
  end
57
57
  </ruby>
58
58
 
59
- The +rbconfig+ file here is out of Ruby's standard library and provides us with the +RbConfig+ class which contains useful information dependent on how Ruby was compiled. We'll see this in use in +railties/lib/rails/script_rails_loader+.
59
+ The +rbconfig+ file from the Ruby standard library provides us with the +RbConfig+ class which contains detailed information about the Ruby environment, including how Ruby was compiled. We can see this in use in +railties/lib/rails/script_rails_loader+.
60
60
 
61
61
  <ruby>
62
62
  require 'pathname'
@@ -71,7 +71,7 @@ module Rails
71
71
  end
72
72
  </ruby>
73
73
 
74
- The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method.
74
+ The +rails/script_rails_loader+ file uses +RbConfig::Config+ to obtain the +bin_dir+ and +ruby_install_name+ values for the configuration which together form the path to the Ruby interpreter. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method.
75
75
 
76
76
  Back in +rails/cli+, the next line is this:
77
77
 
@@ -79,7 +79,7 @@ Back in +rails/cli+, the next line is this:
79
79
  Rails::ScriptRailsLoader.exec_script_rails!
80
80
  </ruby>
81
81
 
82
- This method is defined in +rails/script_rails_loader+ like this:
82
+ This method is defined in +rails/script_rails_loader+:
83
83
 
84
84
  <ruby>
85
85
  def self.exec_script_rails!
@@ -96,7 +96,7 @@ rescue SystemCallError
96
96
  end
97
97
  </ruby>
98
98
 
99
- This method will first check if the current working directory (+cwd+) is a Rails application or is a subdirectory of one. The way to determine this is defined in the +in_rails_application?+ method like this:
99
+ This method will first check if the current working directory (+cwd+) is a Rails application or a subdirectory of one. This is determined by the +in_rails_application?+ method:
100
100
 
101
101
  <ruby>
102
102
  def self.in_rails_application?
@@ -104,7 +104,7 @@ def self.in_rails_application?
104
104
  end
105
105
  </ruby>
106
106
 
107
- The +SCRIPT_RAILS+ constant defined earlier is used here, with +File.exists?+ checking for its presence in the current directory. If this method returns +false+, then +in_rails_application_subdirectory?+ will be used:
107
+ The +SCRIPT_RAILS+ constant defined earlier is used here, with +File.exists?+ checking for its presence in the current directory. If this method returns +false+ then +in_rails_application_subdirectory?+ will be used:
108
108
 
109
109
  <ruby>
110
110
  def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
@@ -112,17 +112,17 @@ def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
112
112
  end
113
113
  </ruby>
114
114
 
115
- This climbs the directory tree until it reaches a path which contains a +script/rails+ file. If a directory is reached which contains this file then this line will run:
115
+ This climbs the directory tree until it reaches a path which contains a +script/rails+ file. If a directory containing this file is reached then this line will run:
116
116
 
117
117
  <ruby>
118
118
  exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application?
119
119
  </ruby>
120
120
 
121
- This is effectively the same as doing +ruby script/rails [arguments]+. Where +[arguments]+ at this point in time is simply "server".
121
+ This is effectively the same as running +ruby script/rails [arguments]+, where +[arguments]+ at this point in time is simply "server".
122
122
 
123
123
  h4. +script/rails+
124
124
 
125
- This file looks like this:
125
+ This file is as follows:
126
126
 
127
127
  <ruby>
128
128
  APP_PATH = File.expand_path('../../config/application', __FILE__)
@@ -130,7 +130,7 @@ require File.expand_path('../../config/boot', __FILE__)
130
130
  require 'rails/commands'
131
131
  </ruby>
132
132
 
133
- The +APP_PATH+ constant here will be used later in +rails/commands+. The +config/boot+ file that +script/rails+ references is the +config/boot.rb+ file in our application which is responsible for loading Bundler and setting it up.
133
+ 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.
134
134
 
135
135
  h4. +config/boot.rb+
136
136
 
@@ -349,10 +349,10 @@ The class *is* defined in +Rack::Server+, but is overwritten in +Rails::Server+
349
349
  def parse!(args)
350
350
  args, options = args.dup, {}
351
351
 
352
- opt_parser = OptionParser.new do |opts|
353
- opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
354
- opts.on("-p", "--port=port", Integer,
355
- "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
352
+ opt_parser = OptionParser.new do |opts|
353
+ opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
354
+ opts.on("-p", "--port=port", Integer,
355
+ "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
356
356
  ...
357
357
  </ruby>
358
358
 
@@ -525,19 +525,19 @@ silence_warnings do
525
525
  end
526
526
  </ruby>
527
527
 
528
- These methods can be used to silence STDERR responses and the +silence_stream+ allows you to also silence other streams. Additionally, this mixin allows you to suppress exceptions and capture streams. For more information see the "Silencing Warnings, Streams, and Exceptions":http://guides.rubyonrails.org/active_support_core_extensions.html#silencing-warnings-streams-and-exceptions section from the Active Support Core Extensions Guide.
528
+ These methods can be used to silence STDERR responses and the +silence_stream+ allows you to also silence other streams. Additionally, this mixin allows you to suppress exceptions and capture streams. For more information see the "Silencing Warnings, Streams, and Exceptions":active_support_core_extensions.html#silencing-warnings-streams-and-exceptions section from the Active Support Core Extensions Guide.
529
529
 
530
530
  h4. +active_support/core_ext/logger.rb+
531
531
 
532
532
  The next file that is required is another Active Support core extension, this time to the +Logger+ class. This begins by defining the +around_[level]+ helpers for the +Logger+ class as well as other methods such as a +datetime_format+ getter and setter for the +formatter+ object tied to a +Logger+ object.
533
533
 
534
- For more information see the "Extensions to Logger":http://guides.rubyonrails.org/active_support_core_extensions.html#extensions-to-logger section from the Active Support Core Extensions Guide.
534
+ For more information see the "Extensions to Logger":active_support_core_extensions.html#extensions-to-logger section from the Active Support Core Extensions Guide.
535
535
 
536
536
  h4. +railties/lib/rails/application.rb+
537
537
 
538
538
  The next file required by +railties/lib/rails.rb+ is +application.rb+. This file defines the +Rails::Application+ constant which the application's class defined in +config/application.rb+ in a standard Rails application depends on. Before the +Rails::Application+ class is defined however, there's some other files that get required first.
539
539
 
540
- The first of these is +active_support/core_ext/hash/reverse_merge+ which can be "read about in the Active Support Core Extensions guide":http://guides.rubyonrails.org/active_support_core_extensions.html#merging under the "Merging" section.
540
+ The first of these is +active_support/core_ext/hash/reverse_merge+ which can be "read about in the Active Support Core Extensions guide":active_support_core_extensions.html#merging under the "Merging" section.
541
541
 
542
542
  h4. +active_support/file_update_checker.rb+
543
543
 
@@ -575,7 +575,7 @@ Now that +rails/initializable.rb+ has finished being required from +rails/railti
575
575
 
576
576
  h4. +railties/lib/rails/configuration.rb+
577
577
 
578
- This file defines the +Rails::Configuration+ module, containing the +MiddlewareStackProxy+ class as well as the +Generators+ class. The +MiddlewareStackProxy+ class is used for managing the middleware stack for an application, which we'll see later on. The +Generators+ class provides the functionality used for configuring what generators an application uses through the "+config.generators+ option":http://guides.rubyonrails.org/configuring.html#configuring-generators.
578
+ This file defines the +Rails::Configuration+ module, containing the +MiddlewareStackProxy+ class as well as the +Generators+ class. The +MiddlewareStackProxy+ class is used for managing the middleware stack for an application, which we'll see later on. The +Generators+ class provides the functionality used for configuring what generators an application uses through the "+config.generators+ option":configuring.html#configuring-generators.
579
579
 
580
580
  The first file required in this file is +activesupport/deprecation+.
581
581
 
@@ -598,11 +598,11 @@ This file defines the +ActiveSupport::Notifications+ module. Notifications provi
598
598
 
599
599
  The "API documentation":http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html for +ActiveSupport::Notifications+ explains the usage of this module, including the methods that it defines.
600
600
 
601
- The file required in +active_support/notifications.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation.
601
+ The file required in +active_support/notifications.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":active_support_core_extensions.html#method-delegation.
602
602
 
603
603
  h4. +activesupport/core_ext/array/wrap+
604
604
 
605
- As this file comprises of a core extension, it is covered exclusively in "the Active Support Core Extensions guide":http://guides.rubyonrails.org/active_support_core_extensions.html#wrapping
605
+ As this file comprises of a core extension, it is covered exclusively in "the Active Support Core Extensions guide":active_support_core_extensions.html#wrapping
606
606
 
607
607
  h4. +activesupport/lib/active_support/deprecation/reporting.rb+
608
608
 
@@ -624,7 +624,7 @@ h4. +active_support/ordered_options+
624
624
 
625
625
  This file is the next file required from +rails/configuration.rb+ is the file that defines +ActiveSupport::OrderedOptions+ which is used for configuration options such as +config.active_support+ and the like.
626
626
 
627
- The next file required is +active_support/core_ext/hash/deep_dup+ which is covered in "Active Support Core Extensions guide":http://guides.rubyonrails.org/active_support_core_extensions.html#deep_dup
627
+ The next file required is +active_support/core_ext/hash/deep_dup+ which is covered in "Active Support Core Extensions guide":active_support_core_extensions.html#deep_dup
628
628
 
629
629
  The file that is required next from is +rails/paths+
630
630
 
@@ -682,7 +682,7 @@ When the module from this file (+Rails::Initializable+) is included, it extends
682
682
 
683
683
  h4. +railties/lib/rails/engine.rb+
684
684
 
685
- The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation.
685
+ The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":active_support_core_extensions.html#method-delegation.
686
686
 
687
687
  The next two files after this are Ruby standard library files: +pathname+ and +rbconfig+. The file after these is +rails/engine/railties+.
688
688
 
@@ -698,7 +698,7 @@ Once this file has finished loading we jump back to +railties/lib/rails/plugin.r
698
698
 
699
699
  h4. Back to +railties/lib/rails/plugin.rb+
700
700
 
701
- The next file required in this is a core extension from Active Support called +array/conversions+ which is covered in "this section":http://guides.rubyonrails.org/active_support_core_extensions.html#array-conversions of the Active Support Core Extensions Guide.
701
+ The next file required in this is a core extension from Active Support called +array/conversions+ which is covered in "this section":active_support_core_extensions.html#array-conversions of the Active Support Core Extensions Guide.
702
702
 
703
703
  Once that file has finished loading, the +Rails::Plugin+ class is defined.
704
704
 
@@ -817,7 +817,7 @@ def initializer(name, opts = {}, &blk)
817
817
  end
818
818
  </ruby>
819
819
 
820
- An initializer can be configured to run before or after another initializer, which we'll see a couple of times throughout this initialization process. Anything that inherits from +Rails::Railtie+ may also make use of the +initializer+ method, something which is covered in the "Configuration guide":[http://ryanbigg.com/guides/configuring.html#rails-railtie-initializer].
820
+ An initializer can be configured to run before or after another initializer, which we'll see a couple of times throughout this initialization process. Anything that inherits from +Rails::Railtie+ may also make use of the +initializer+ method, something which is covered in the "Configuration guide":configuring.html#rails-railtie-initializer.
821
821
 
822
822
  The +Initializer+ class here is defined within the +Rails::Initializable+ module and its +initialize+ method is defined to just set up a couple of variables:
823
823
 
@@ -90,7 +90,7 @@ If we want to display the properties of all the books in our view, we can do so
90
90
  <%= link_to 'New book', new_book_path %>
91
91
  </ruby>
92
92
 
93
- NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. In Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), and +.builder+ for Builder (XML generator).
93
+ NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. Beginning with Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), and +.builder+ for Builder (XML generator).
94
94
 
95
95
  h4. Using +render+
96
96
 
@@ -334,7 +334,7 @@ render :status => 500
334
334
  render :status => :forbidden
335
335
  </ruby>
336
336
 
337
- Rails understands both numeric status codes and symbols for status codes.
337
+ Rails understands both numeric and symbolic status codes.
338
338
 
339
339
  h6. The +:location+ Option
340
340
 
@@ -348,9 +348,9 @@ h5. Finding Layouts
348
348
 
349
349
  To find the current layout, Rails first looks for a file in +app/views/layouts+ with the same base name as the controller. For example, rendering actions from the +PhotosController+ class will use +app/views/layouts/photos.html.erb+ (or +app/views/layouts/photos.builder+). If there is no such controller-specific layout, Rails will use +app/views/layouts/application.html.erb+ or +app/views/layouts/application.builder+. If there is no +.erb+ layout, Rails will use a +.builder+ layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.
350
350
 
351
- h6. Specifying Layouts on a per-Controller Basis
351
+ h6. Specifying Layouts for Controllers
352
352
 
353
- You can override the automatic layout conventions in your controllers by using the +layout+ declaration in the controller. For example:
353
+ You can override the default layout conventions in your controllers by using the +layout+ declaration. For example:
354
354
 
355
355
  <ruby>
356
356
  class ProductsController < ApplicationController
@@ -359,9 +359,9 @@ class ProductsController < ApplicationController
359
359
  end
360
360
  </ruby>
361
361
 
362
- With this declaration, all methods within +ProductsController+ will use +app/views/layouts/inventory.html.erb+ for their layout.
362
+ With this declaration, all of the methods within +ProductsController+ will use +app/views/layouts/inventory.html.erb+ for their layout.
363
363
 
364
- To assign a specific layout for the entire application, use a declaration in your +ApplicationController+ class:
364
+ To assign a specific layout for the entire application, use a +layout+ declaration in your +ApplicationController+ class:
365
365
 
366
366
  <ruby>
367
367
  class ApplicationController < ActionController::Base
@@ -370,7 +370,7 @@ class ApplicationController < ActionController::Base
370
370
  end
371
371
  </ruby>
372
372
 
373
- With this declaration, all views in the entire application will use +app/views/layouts/main.html.erb+ for their layout.
373
+ With this declaration, all of the views in the entire application will use +app/views/layouts/main.html.erb+ for their layout.
374
374
 
375
375
  h6. Choosing Layouts at Runtime
376
376
 
@@ -392,9 +392,9 @@ class ProductsController < ApplicationController
392
392
  end
393
393
  </ruby>
394
394
 
395
- Now, if the current user is a special user, they'll get a special layout when viewing a product. You can even use an inline method to determine the layout:
395
+ Now, if the current user is a special user, they'll get a special layout when viewing a product.
396
396
 
397
- You can also decide the layout by passing a Proc object, the block you give the Proc will be given the +controller+ instance, so you can make decisions based on the current request. For example:
397
+ You can even use an inline method, such as a Proc, to determine the layout. For example, if you pass a Proc object, the block you give the Proc will be given the +controller+ instance, so the layout can be determined based on the current request:
398
398
 
399
399
  <ruby>
400
400
  class ProductsController < ApplicationController
@@ -404,7 +404,7 @@ end
404
404
 
405
405
  h6. Conditional Layouts
406
406
 
407
- Layouts specified at the controller level support +:only+ and +:except+ options that take either a method name or an array of method names which correspond to method names within the controller:
407
+ Layouts specified at the controller level support the +:only+ and +:except+ options. These options take either a method name, or an array of method names, corresponding to method names within the controller:
408
408
 
409
409
  <ruby>
410
410
  class ProductsController < ApplicationController
@@ -416,7 +416,7 @@ With this declaration, the +product+ layout would be used for everything but the
416
416
 
417
417
  h6. Layout Inheritance
418
418
 
419
- Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example:
419
+ Layout declarations cascade downward in the hierarchy, and more specific layout declarations always override more general ones. For example:
420
420
 
421
421
  * +application_controller.rb+
422
422
 
@@ -495,9 +495,9 @@ def show
495
495
  end
496
496
  </ruby>
497
497
 
498
- Make sure you use +and return+ and not +&amp;&amp; return+ because while the former will work, the latter will not due to operator precedence in the Ruby Language.
498
+ Make sure to use +and return+ instead of +&amp;&amp; return+ because +&amp;&amp; return+ will not work due to the operator precedence in the Ruby Language.
499
499
 
500
- Note that the implicit render done by ActionController detects if +render+ has been called, and thus avoids this error. Therefore, the following will work without errors:
500
+ Note that the implicit render done by ActionController detects if +render+ has been called, so the following will work without errors:
501
501
 
502
502
  <ruby>
503
503
  def show
@@ -515,10 +515,10 @@ h4. Using +redirect_to+
515
515
  Another way to handle returning responses to an HTTP request is with +redirect_to+. As you've seen, +render+ tells Rails which view (or other asset) to use in constructing a response. The +redirect_to+ method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:
516
516
 
517
517
  <ruby>
518
- redirect_to photos_path
518
+ redirect_to photos_url
519
519
  </ruby>
520
520
 
521
- You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. In addition, there's a special redirect that sends the user back to the page they just came from:
521
+ You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. There's also a special redirect that sends the user back to the page they just came from:
522
522
 
523
523
  <ruby>
524
524
  redirect_to :back
@@ -526,7 +526,7 @@ redirect_to :back
526
526
 
527
527
  h5. Getting a Different Redirect Status Code
528
528
 
529
- Rails uses HTTP status code 302 (temporary redirect) when you call +redirect_to+. If you'd like to use a different status code (perhaps 301, permanent redirect), you can do so by using the +:status+ option:
529
+ Rails uses HTTP status code 302, a temporary redirect, when you call +redirect_to+. If you'd like to use a different status code, perhaps 301, a permanent redirect, you can use the +:status+ option:
530
530
 
531
531
  <ruby>
532
532
  redirect_to photos_path, :status => 301
@@ -536,7 +536,7 @@ Just like the +:status+ option for +render+, +:status+ for +redirect_to+ accepts
536
536
 
537
537
  h5. The Difference Between +render+ and +redirect_to+
538
538
 
539
- Sometimes inexperienced developers conceive of +redirect_to+ as a sort of +goto+ command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back an HTTP 302 status code.
539
+ Sometimes inexperienced developers think of +redirect_to+ as a sort of +goto+ command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back an HTTP 302 status code.
540
540
 
541
541
  Consider these actions to see the difference:
542
542
 
@@ -553,7 +553,7 @@ def show
553
553
  end
554
554
  </ruby>
555
555
 
556
- With the code in this form, there will likely be a problem if the +@book+ variable is +nil+. Remember, a +render :action+ doesn't run any code in the target action, so nothing will set up the +@books+ variable that the +index+ view is presumably depending on. One way to fix this is to redirect instead of rendering:
556
+ With the code in this form, there will likely be a problem if the +@book+ variable is +nil+. Remember, a +render :action+ doesn't run any code in the target action, so nothing will set up the +@books+ variable that the +index+ view will probably require. One way to fix this is to redirect instead of rendering:
557
557
 
558
558
  <ruby>
559
559
  def index
@@ -570,9 +570,9 @@ end
570
570
 
571
571
  With this code, the browser will make a fresh request for the index page, the code in the +index+ method will run, and all will be well.
572
572
 
573
- The only downside to this code, is that it requires a round trip to the browser, the browser requested the show action with +/books/1+ and the controller finds that there are no books, so the controller sends out a 302 redirect response to the browser telling it to go to +/books/+, the browser complies and sends a new request back to the controller asking now for the +index+ action, the controller then gets all the books in the database and renders the index template, sending it back down to the browser which then shows it on your screen.
573
+ The only downside to this code is that it requires a round trip to the browser: the browser requested the show action with +/books/1+ and the controller finds that there are no books, so the controller sends out a 302 redirect response to the browser telling it to go to +/books/+, the browser complies and sends a new request back to the controller asking now for the +index+ action, the controller then gets all the books in the database and renders the index template, sending it back down to the browser which then shows it on your screen.
574
574
 
575
- While in a small app, this added latency might not be a problem, it is something to think about when speed of response is of the essence. One way to handle this double request (though a contrived example) could be:
575
+ While in a small application, this added latency might not be a problem, it is something to think about if response time is a concern. We can demonstrate one way to handle this with a contrived example:
576
576
 
577
577
  <ruby>
578
578
  def index
@@ -588,7 +588,7 @@ def show
588
588
  end
589
589
  </ruby>
590
590
 
591
- Which would detect that there are no books, populate the +@books+ instance variable with all the books in the database and then directly render the +index.html.erb+ template returning it to the browser with a flash alert message telling the user what happened.
591
+ This would detect that there are no books with the specified ID, populate the +@books+ instance variable with all the books in the model, and then directly render the +index.html.erb+ template, returning it to the browser with a flash alert message to tell the user what happened.
592
592
 
593
593
  h4. Using +head+ To Build Header-Only Responses
594
594
 
@@ -598,7 +598,7 @@ The +head+ method can be used to send responses with only headers to the browser
598
598
  head :bad_request
599
599
  </ruby>
600
600
 
601
- Which would produce the following header:
601
+ This would produce the following header:
602
602
 
603
603
  <shell>
604
604
  HTTP/1.1 400 Bad Request
@@ -611,7 +611,7 @@ Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
611
611
  Cache-Control: no-cache
612
612
  </shell>
613
613
 
614
- Or you can use other HTTP headers to convey additional information:
614
+ Or you can use other HTTP headers to convey other information:
615
615
 
616
616
  <ruby>
617
617
  head :created, :location => photo_path(@photo)
@@ -633,15 +633,15 @@ Cache-Control: no-cache
633
633
 
634
634
  h3. Structuring Layouts
635
635
 
636
- When Rails renders a view as a response, it does so by combining the view with the current layout (using the rules for finding the current layout that were covered earlier in this guide). Within a layout, you have access to three tools for combining different bits of output to form the overall response:
636
+ When Rails renders a view as a response, it does so by combining the view with the current layout, using the rules for finding the current layout that were covered earlier in this guide. Within a layout, you have access to three tools for combining different bits of output to form the overall response:
637
637
 
638
638
  * Asset tags
639
639
  * +yield+ and +content_for+
640
640
  * Partials
641
641
 
642
- h4. Asset Tags
642
+ h4. Asset Tag Helpers
643
643
 
644
- Asset tags provide methods for generating HTML that links views to feeds, JavaScript, stylesheets, images, videos and audios. These are the six asset tags available in Rails:
644
+ Asset tag helpers provide methods for generating HTML that link views to feeds, JavaScript, stylesheets, images, videos and audios. There are six asset tag helpers available in Rails:
645
645
 
646
646
  * +auto_discovery_link_tag+
647
647
  * +javascript_include_tag+
@@ -650,11 +650,11 @@ Asset tags provide methods for generating HTML that links views to feeds, JavaSc
650
650
  * +video_tag+
651
651
  * +audio_tag+
652
652
 
653
- You can use these tags in layouts or other views, although the tags other than +image_tag+ are most commonly used in the +&lt;head&gt;+ section of a layout.
653
+ You can use these tags in layouts or other views, although the +auto_discovery_link_tag+, +javascript_include_tag+, and +stylesheet_link_tag+, are most commonly used in the +&lt;head&gt;+ section of a layout.
654
654
 
655
- WARNING: The asset tags do _not_ verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link.
655
+ WARNING: The asset tag helpers do _not_ verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link.
656
656
 
657
- h5. Linking to Feeds with +auto_discovery_link_tag+
657
+ h5. Linking to Feeds with the +auto_discovery_link_tag+
658
658
 
659
659
  The +auto_discovery_link_tag+ helper builds HTML that most browsers and newsreaders can use to detect the presences of RSS or ATOM feeds. It takes the type of the link (+:rss+ or +:atom+), a hash of options that are passed through to url_for, and a hash of options for the tag:
660
660
 
@@ -663,27 +663,41 @@ The +auto_discovery_link_tag+ helper builds HTML that most browsers and newsread
663
663
  {:title => "RSS Feed"}) %>
664
664
  </erb>
665
665
 
666
- There are three tag options available for +auto_discovery_link_tag+:
666
+ There are three tag options available for the +auto_discovery_link_tag+:
667
667
 
668
- * +:rel+ specifies the +rel+ value in the link (defaults to "alternate")
668
+ * +:rel+ specifies the +rel+ value in the link. The default value is "alternate".
669
669
  * +:type+ specifies an explicit MIME type. Rails will generate an appropriate MIME type automatically.
670
- * +:title+ specifies the title of the link
670
+ * +:title+ specifies the title of the link. The default value is the upshifted +:type+ value, for example, "ATOM" or "RSS".
671
671
 
672
- h5. Linking to JavaScript Files with +javascript_include_tag+
672
+ h5. Linking to JavaScript Files with the +javascript_include_tag+
673
673
 
674
- The +javascript_include_tag+ helper returns an HTML +script+ tag for each source provided. Rails looks in +public/javascripts+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/javascripts/main.js+:
674
+ The +javascript_include_tag+ helper returns an HTML +script+ tag for each source provided.
675
+
676
+ If you are using Rails with the "Asset Pipeline":asset_pipeline.html enabled, this helper will generate a link to +/assets/javascripts/+ rather than +public/javascripts+ which was used in earlier versions of Rails. This link is then served by the Sprockets gem, which was introduced in Rails 3.1.
677
+
678
+ A JavaScript file within a Rails application or Rails engine goes in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+. These locations are explained in detail in the "Asset Organization section in the Asset Pipeline Guide":asset_pipeline.html#asset-organization
679
+
680
+ You can specify a full path relative to the document root, or a URL, if you prefer. For example, to link to a JavaScript file that is inside a directory called +javascripts+ inside of one of +app/assets+, +lib/assets+ or +vendor/assets+, you would do this:
675
681
 
676
682
  <erb>
677
683
  <%= javascript_include_tag "main" %>
678
684
  </erb>
679
685
 
680
- To include +public/javascripts/main.js+ and +public/javascripts/columns.js+:
686
+ Rails will then output a +script+ tag such as this:
687
+
688
+ <html>
689
+ <script src='/assets/main.js' type="text/javascript"></script>
690
+ </html>
691
+
692
+ The request to this asset is then served by the Sprockets gem.
693
+
694
+ To include multiple files such as +app/assets/javascripts/main.js+ and +app/assets/javascripts/columns.js+ at the same time:
681
695
 
682
696
  <erb>
683
697
  <%= javascript_include_tag "main", "columns" %>
684
698
  </erb>
685
699
 
686
- To include +public/javascripts/main.js+ and +public/photos/columns.js+:
700
+ To include +app/assets/javascripts/main.js+ and +app/assets/javascripts/photos/columns.js+:
687
701
 
688
702
  <erb>
689
703
  <%= javascript_include_tag "main", "/photos/columns" %>
@@ -701,15 +715,38 @@ If the application does not use the asset pipeline, the +:defaults+ option loads
701
715
  <%= javascript_include_tag :defaults %>
702
716
  </erb>
703
717
 
704
- And you can in any case override the expansion in <tt>config/application.rb</tt>:
718
+ Outputting +script+ tags such as this:
719
+
720
+ <html>
721
+ <script src="/javascripts/jquery.js" type="text/javascript"></script>
722
+ <script src="/javascripts/jquery_ujs.js" type="text/javascript"></script>
723
+ </html>
724
+
725
+ These two files for jQuery, +jquery.js+ and +jquery_ujs.js+ must be placed inside +public/javascripts+ if the application doesn't use the asset pipeline. These files can be downloaded from the "jquery-rails repository on GitHub":https://github.com/indirect/jquery-rails/tree/master/vendor/assets/javascripts
726
+
727
+ WARNING: If you are using the asset pipeline, this tag will render a +script+ tag for an asset called +defaults.js+, which would not exist in your application unless you've explicitly defined it to be.
728
+
729
+ And you can in any case override the +:defaults+ expansion in <tt>config/application.rb</tt>:
705
730
 
706
731
  <ruby>
707
732
  config.action_view.javascript_expansions[:defaults] = %w(foo.js bar.js)
708
733
  </ruby>
709
734
 
710
- When using <tt>:defaults</tt>, if an <tt>application.js</tt> file exists in <tt>public/javascripts</tt> it will be included as well at then end.
735
+ You can also define new defaults:
736
+
737
+ <ruby>
738
+ config.action_view.javascript_expansions[:projects] = %w(projects.js tickets.js)
739
+ </ruby>
740
+
741
+ And use them by referencing them exactly like +:defaults+:
742
+
743
+ <erb>
744
+ <%= javascript_include_tag :projects %>
745
+ </erb>
711
746
 
712
- Also, the +:all+ option loads every JavaScript file in +public/javascripts+:
747
+ When using <tt>:defaults</tt>, if an <tt>application.js</tt> file exists in <tt>public/javascripts</tt> it will be included as well at the end.
748
+
749
+ Also, if the asset pipeline is disabled, the +:all+ expansion loads every JavaScript file in +public/javascripts+:
713
750
 
714
751
  <erb>
715
752
  <%= javascript_include_tag :all %>
@@ -738,21 +775,25 @@ By default, the combined file will be delivered as +javascripts/all.js+. You can
738
775
 
739
776
  You can even use dynamic paths such as +cache/#{current_site}/main/display+.
740
777
 
741
- h5. Linking to CSS Files with +stylesheet_link_tag+
778
+ h5. Linking to CSS Files with the +stylesheet_link_tag+
779
+
780
+ The +stylesheet_link_tag+ helper returns an HTML +&lt;link&gt;+ tag for each source provided.
742
781
 
743
- The +stylesheet_link_tag+ helper returns an HTML +&lt;link&gt;+ tag for each source provided. Rails looks in +public/stylesheets+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/stylesheets/main.css+:
782
+ If you are using Rails with the "Asset Pipeline" enabled, this helper will generate a link to +/assets/stylesheets/+. This link is then processed by the Sprockets gem. A stylesheet file can be stored in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+.
783
+
784
+ You can specify a full path relative to the document root, or a URL. For example, to link to a stylesheet file that is inside a directory called +stylesheets+ inside of one of +app/assets+, +lib/assets+ or +vendor/assets+, you would do this:
744
785
 
745
786
  <erb>
746
787
  <%= stylesheet_link_tag "main" %>
747
788
  </erb>
748
789
 
749
- To include +public/stylesheets/main.css+ and +public/stylesheets/columns.css+:
790
+ To include +app/assets/stylesheets/main.css+ and +app/assets/stylesheets/columns.css+:
750
791
 
751
792
  <erb>
752
793
  <%= stylesheet_link_tag "main", "columns" %>
753
794
  </erb>
754
795
 
755
- To include +public/stylesheets/main.css+ and +public/photos/columns.css+:
796
+ To include +app/assets/stylesheets/main.css+ and +app/assets/stylesheets/photos/columns.css+:
756
797
 
757
798
  <erb>
758
799
  <%= stylesheet_link_tag "main", "/photos/columns" %>
@@ -764,13 +805,13 @@ To include +http://example.com/main.css+:
764
805
  <%= stylesheet_link_tag "http://example.com/main.css" %>
765
806
  </erb>
766
807
 
767
- By default, +stylesheet_link_tag+ creates links with +media="screen" rel="stylesheet" type="text/css"+. You can override any of these defaults by specifying an appropriate option (+:media+, +:rel+, or +:type+):
808
+ By default, the +stylesheet_link_tag+ creates links with +media="screen" rel="stylesheet" type="text/css"+. You can override any of these defaults by specifying an appropriate option (+:media+, +:rel+, or +:type+):
768
809
 
769
810
  <erb>
770
811
  <%= stylesheet_link_tag "main_print", :media => "print" %>
771
812
  </erb>
772
813
 
773
- The +all+ option links every CSS file in +public/stylesheets+:
814
+ If the asset pipeline is disabled, the +all+ option links every CSS file in +public/stylesheets+:
774
815
 
775
816
  <erb>
776
817
  <%= stylesheet_link_tag :all %>
@@ -797,7 +838,7 @@ By default, the combined file will be delivered as +stylesheets/all.css+. You ca
797
838
 
798
839
  You can even use dynamic paths such as +cache/#{current_site}/main/display+.
799
840
 
800
- h5. Linking to Images with +image_tag+
841
+ h5. Linking to Images with the +image_tag+
801
842
 
802
843
  The +image_tag+ helper builds an HTML +&lt;img /&gt;+ tag to the specified file. By default, files are loaded from +public/images+.
803
844
 
@@ -846,7 +887,7 @@ In addition to the above special tags, you can supply a final hash of standard H
846
887
  :class => 'nav_bar' %>
847
888
  </erb>
848
889
 
849
- h5. Linking to Videos with +video_tag+
890
+ h5. Linking to Videos with the +video_tag+
850
891
 
851
892
  The +video_tag+ helper builds an HTML 5 +&lt;video&gt;+ tag to the specified file. By default, files are loaded from +public/videos+.
852
893
 
@@ -882,7 +923,7 @@ This will produce:
882
923
  <video><source src="trailer.ogg" /><source src="movie.ogg" /></video>
883
924
  </erb>
884
925
 
885
- h5. Linking to Audio files with +audio_tag+
926
+ h5. Linking to Audio Files with the +audio_tag+
886
927
 
887
928
  The +audio_tag+ helper builds an HTML 5 +&lt;audio&gt;+ tag to the specified file. By default, files are loaded from +public/audios+.
888
929
 
@@ -933,7 +974,7 @@ You can also create a layout with multiple yielding regions:
933
974
 
934
975
  The main body of the view will always render into the unnamed +yield+. To render content into a named +yield+, you use the +content_for+ method.
935
976
 
936
- h4. Using +content_for+
977
+ h4. Using the +content_for+ Method
937
978
 
938
979
  The +content_for+ method allows you to insert content into a named +yield+ block in your layout. For example, this view would work with the layout that you just saw:
939
980
 
@@ -1093,6 +1134,13 @@ In Rails 3.0, there is also a shorthand for this. Assuming +@products+ is a coll
1093
1134
 
1094
1135
  Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:
1095
1136
 
1137
+ In the event that the collection is empty, +render+ will return nil, so it should be fairly simple to provide alternative content.
1138
+
1139
+ <erb>
1140
+ <h1>Products</h1>
1141
+ <%= render(@products) || 'There are no products available.' %>
1142
+ </erb>
1143
+
1096
1144
  * +index.html.erb+
1097
1145
 
1098
1146
  <erb>
@@ -1187,15 +1235,3 @@ On pages generated by +NewsController+, you want to hide the top menu and add a
1187
1235
  That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div.
1188
1236
 
1189
1237
  There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +content_for?(:news_content) ? yield(:news_content) : yield+ with simply +yield+.
1190
-
1191
- h3. Changelog
1192
-
1193
- * April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
1194
- * January 25, 2010: Rails 3.0 Update by "Mikel Lindsaar":credits.html#raasdnil
1195
- * December 27, 2008: Merge patch from Rodrigo Rosenfeld Rosas covering subtemplates
1196
- * December 27, 2008: Information on new rendering defaults by "Mike Gunderloy":credits.html#mgunderloy
1197
- * November 9, 2008: Added partial collection counter by "Mike Gunderloy":credits.html#mgunderloy
1198
- * November 1, 2008: Added +:js+ option for +render+ by "Mike Gunderloy":credits.html#mgunderloy
1199
- * October 16, 2008: Ready for publication by "Mike Gunderloy":credits.html#mgunderloy
1200
- * October 4, 2008: Additional info on partials (+:object+, +:as+, and +:spacer_template+) by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)
1201
- * September 28, 2008: First draft by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)