rails 4.1.14.2 → 4.2.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +12 -10
  3. data/guides/CHANGELOG.md +34 -37
  4. data/guides/Rakefile +21 -6
  5. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  6. data/guides/assets/javascripts/guides.js +6 -0
  7. data/guides/assets/stylesheets/main.css +4 -1
  8. data/guides/bug_report_templates/action_controller_gem.rb +1 -1
  9. data/guides/bug_report_templates/action_controller_master.rb +1 -0
  10. data/guides/bug_report_templates/active_record_gem.rb +1 -1
  11. data/guides/bug_report_templates/generic_gem.rb +1 -1
  12. data/guides/rails_guides/helpers.rb +1 -1
  13. data/guides/rails_guides/levenshtein.rb +27 -21
  14. data/guides/rails_guides/markdown/renderer.rb +1 -1
  15. data/guides/rails_guides/markdown.rb +11 -7
  16. data/guides/rails_guides.rb +2 -2
  17. data/guides/source/2_2_release_notes.md +1 -1
  18. data/guides/source/2_3_release_notes.md +4 -4
  19. data/guides/source/3_0_release_notes.md +8 -8
  20. data/guides/source/3_1_release_notes.md +5 -2
  21. data/guides/source/3_2_release_notes.md +6 -3
  22. data/guides/source/4_0_release_notes.md +6 -3
  23. data/guides/source/4_1_release_notes.md +5 -6
  24. data/guides/source/4_2_release_notes.md +877 -0
  25. data/guides/source/_license.html.erb +1 -1
  26. data/guides/source/_welcome.html.erb +6 -8
  27. data/guides/source/action_controller_overview.md +25 -8
  28. data/guides/source/action_mailer_basics.md +97 -29
  29. data/guides/source/action_view_overview.md +142 -183
  30. data/guides/source/active_job_basics.md +339 -0
  31. data/guides/source/active_model_basics.md +371 -17
  32. data/guides/source/active_record_basics.md +25 -24
  33. data/guides/source/active_record_callbacks.md +12 -9
  34. data/guides/source/{migrations.md → active_record_migrations.md} +95 -220
  35. data/guides/source/active_record_postgresql.md +433 -0
  36. data/guides/source/active_record_querying.md +264 -268
  37. data/guides/source/active_record_validations.md +23 -13
  38. data/guides/source/active_support_core_extensions.md +114 -75
  39. data/guides/source/active_support_instrumentation.md +10 -18
  40. data/guides/source/api_documentation_guidelines.md +63 -17
  41. data/guides/source/asset_pipeline.md +258 -119
  42. data/guides/source/association_basics.md +96 -80
  43. data/guides/source/autoloading_and_reloading_constants.md +1311 -0
  44. data/guides/source/caching_with_rails.md +32 -7
  45. data/guides/source/command_line.md +52 -30
  46. data/guides/source/configuring.md +161 -33
  47. data/guides/source/contributing_to_ruby_on_rails.md +198 -114
  48. data/guides/source/credits.html.erb +2 -2
  49. data/guides/source/debugging_rails_applications.md +440 -286
  50. data/guides/source/development_dependencies_install.md +47 -36
  51. data/guides/source/documents.yaml +19 -7
  52. data/guides/source/engines.md +189 -189
  53. data/guides/source/form_helpers.md +79 -56
  54. data/guides/source/generators.md +24 -11
  55. data/guides/source/getting_started.md +359 -219
  56. data/guides/source/i18n.md +110 -66
  57. data/guides/source/index.html.erb +1 -0
  58. data/guides/source/initialization.md +109 -62
  59. data/guides/source/layout.html.erb +5 -11
  60. data/guides/source/layouts_and_rendering.md +26 -26
  61. data/guides/source/maintenance_policy.md +6 -3
  62. data/guides/source/nested_model_forms.md +7 -4
  63. data/guides/source/plugins.md +27 -27
  64. data/guides/source/rails_application_templates.md +21 -3
  65. data/guides/source/rails_on_rack.md +8 -5
  66. data/guides/source/routing.md +113 -73
  67. data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
  68. data/guides/source/security.md +39 -33
  69. data/guides/source/testing.md +199 -119
  70. data/guides/source/upgrading_ruby_on_rails.md +287 -29
  71. data/guides/source/working_with_javascript_in_rails.md +19 -17
  72. data/guides/w3c_validator.rb +2 -0
  73. metadata +40 -95
  74. data/guides/code/getting_started/Gemfile +0 -40
  75. data/guides/code/getting_started/Gemfile.lock +0 -125
  76. data/guides/code/getting_started/README.rdoc +0 -28
  77. data/guides/code/getting_started/Rakefile +0 -6
  78. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  79. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  80. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  81. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  82. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  83. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  84. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  85. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  86. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  87. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  88. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  89. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  90. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  91. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  92. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  93. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  94. data/guides/code/getting_started/app/models/comment.rb +0 -3
  95. data/guides/code/getting_started/app/models/post.rb +0 -7
  96. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  97. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  98. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  99. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  100. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  101. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  102. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  103. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  104. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  105. data/guides/code/getting_started/bin/bundle +0 -4
  106. data/guides/code/getting_started/bin/rails +0 -4
  107. data/guides/code/getting_started/bin/rake +0 -4
  108. data/guides/code/getting_started/config/application.rb +0 -18
  109. data/guides/code/getting_started/config/boot.rb +0 -4
  110. data/guides/code/getting_started/config/database.yml +0 -25
  111. data/guides/code/getting_started/config/environment.rb +0 -5
  112. data/guides/code/getting_started/config/environments/development.rb +0 -30
  113. data/guides/code/getting_started/config/environments/production.rb +0 -80
  114. data/guides/code/getting_started/config/environments/test.rb +0 -36
  115. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  116. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  117. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  118. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  119. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  120. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  121. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  122. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  123. data/guides/code/getting_started/config/locales/en.yml +0 -23
  124. data/guides/code/getting_started/config/routes.rb +0 -7
  125. data/guides/code/getting_started/config.ru +0 -4
  126. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  127. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  128. data/guides/code/getting_started/db/schema.rb +0 -33
  129. data/guides/code/getting_started/db/seeds.rb +0 -7
  130. data/guides/code/getting_started/public/404.html +0 -60
  131. data/guides/code/getting_started/public/422.html +0 -60
  132. data/guides/code/getting_started/public/500.html +0 -59
  133. data/guides/code/getting_started/public/favicon.ico +0 -0
  134. data/guides/code/getting_started/public/robots.txt +0 -5
  135. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  136. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  137. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  138. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  139. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  140. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  141. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  142. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  143. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  144. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  145. data/guides/code/getting_started/test/test_helper.rb +0 -12
@@ -28,7 +28,7 @@ After reading this guide, you will know:
28
28
 
29
29
  --------------------------------------------------------------------------------
30
30
 
31
- NOTE: The Ruby I18n framework provides you with all necessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See the Ruby [I18n Wiki](http://ruby-i18n.org/wiki) for more information.
31
+ NOTE: The Ruby I18n framework provides you with all necessary means for internationalization/localization of your Rails application. You may, also use various gems available to add additional functionality or features. See the [rails-i18n gem](https://github.com/svenfuchs/rails-i18n) for more information.
32
32
 
33
33
  How I18n in Ruby on Rails Works
34
34
  -------------------------------
@@ -92,7 +92,7 @@ Rails adds all `.rb` and `.yml` files from the `config/locales` directory to you
92
92
 
93
93
  The default `en.yml` locale in this directory contains a sample pair of translation strings:
94
94
 
95
- ```ruby
95
+ ```yaml
96
96
  en:
97
97
  hello: "Hello world"
98
98
  ```
@@ -101,13 +101,13 @@ This means, that in the `:en` locale, the key _hello_ will map to the _Hello wor
101
101
 
102
102
  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.
103
103
 
104
- 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 [Globalize3](https://github.com/globalize/globalize) may help you implement it.
104
+ 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. Few gems such as [Globalize3](https://github.com/globalize/globalize) may help you implement it.
105
105
 
106
106
  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.
107
107
 
108
108
  NOTE: The backend will lazy-load these translations when a translation is looked up for the first time. This makes it possible to just swap the backend with something else even after translations have already been announced.
109
109
 
110
- The default `application.rb` files has instructions on how to add locales from another directory and how to set a different default locale. Just uncomment and edit the specific lines.
110
+ The default `application.rb` file has instructions on how to add locales from another directory and how to set a different default locale. Just uncomment and edit the specific lines.
111
111
 
112
112
  ```ruby
113
113
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
@@ -137,7 +137,7 @@ If you want to translate your Rails application to a **single language other tha
137
137
 
138
138
  However, you would probably like to **provide support for more locales** in your application. In such case, you need to set and pass the locale between requests.
139
139
 
140
- WARNING: You may be tempted to store the chosen locale in a _session_ or a <em>cookie</em>, however **do not do this**. The locale should be transparent and a part of the URL. This way you won't break people's basic assumptions about the web itself: if you send a URL to a friend, they should see the same page and content as you. A fancy word for this would be that you're being [<em>RESTful</em>](http://en.wikipedia.org/wiki/Representational_State_Transfer). Read more about the RESTful approach in [Stefan Tilkov's articles](http://www.infoq.com/articles/rest-introduction). Sometimes there are exceptions to this rule and those are discussed below.
140
+ WARNING: You may be tempted to store the chosen locale in a _session_ or a *cookie*. However, **do not do this**. The locale should be transparent and a part of the URL. This way you won't break people's basic assumptions about the web itself: if you send a URL to a friend, they should see the same page and content as you. A fancy word for this would be that you're being [*RESTful*](http://en.wikipedia.org/wiki/Representational_State_Transfer). Read more about the RESTful approach in [Stefan Tilkov's articles](http://www.infoq.com/articles/rest-introduction). Sometimes there are exceptions to this rule and those are discussed below.
141
141
 
142
142
  The _setting part_ is easy. You can set the locale in a `before_action` in the `ApplicationController` like this:
143
143
 
@@ -212,17 +212,16 @@ The most usual way of setting (and passing) the locale would be to include it in
212
212
 
213
213
  This approach has almost the same set of advantages as setting the locale from the domain name: namely that it's RESTful and in accord with the rest of the World Wide Web. It does require a little bit more work to implement, though.
214
214
 
215
- Getting the locale from `params` and setting it accordingly is not hard; including it in every URL and thus **passing it through the requests** is. To include an explicit option in every URL (e.g. `link_to( books_url(locale: I18n.locale))`) would be tedious and probably impossible, of course.
215
+ Getting the locale from `params` and setting it accordingly is not hard; including it in every URL and thus **passing it through the requests** is. To include an explicit option in every URL, e.g. `link_to(books_url(locale: I18n.locale))`, would be tedious and probably impossible, of course.
216
216
 
217
- Rails contains infrastructure for "centralizing dynamic decisions about the URLs" in its [`ApplicationController#default_url_options`](http://api.rubyonrails.org/classes/ActionController/Base.html#M000515), which is useful precisely in this scenario: it enables us to set "defaults" for [`url_for`](http://api.rubyonrails.org/classes/ActionController/Base.html#M000503) and helper methods dependent on it (by implementing/overriding this method).
217
+ Rails contains infrastructure for "centralizing dynamic decisions about the URLs" in its [`ApplicationController#default_url_options`](http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Base.html#method-i-default_url_options), which is useful precisely in this scenario: it enables us to set "defaults" for [`url_for`](http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html#method-i-url_for) and helper methods dependent on it (by implementing/overriding this method).
218
218
 
219
219
  We can include something like this in our `ApplicationController` then:
220
220
 
221
221
  ```ruby
222
222
  # app/controllers/application_controller.rb
223
- def default_url_options(options={})
224
- logger.debug "default_url_options is passed options: #{options.inspect}\n"
225
- { locale: I18n.locale }
223
+ def default_url_options(options = {})
224
+ { locale: I18n.locale }.merge options
226
225
  end
227
226
  ```
228
227
 
@@ -263,7 +262,7 @@ get '/:locale' => 'dashboard#index'
263
262
 
264
263
  Do take special care about the **order of your routes**, so this route declaration does not "eat" other ones. (You may want to add it directly before the `root :to` declaration.)
265
264
 
266
- NOTE: Have a look at two plugins which simplify work with routes in this way: Sven Fuchs's [routing_filter](https://github.com/svenfuchs/routing-filter/tree/master) and Raul Murciano's [translate_routes](https://github.com/raul/translate_routes/tree/master).
265
+ NOTE: Have a look at various gems which simplify working with routes: [routing_filter](https://github.com/svenfuchs/routing-filter/tree/master), [rails-translate-routes](https://github.com/francesc/rails-translate-routes), [route_translator](https://github.com/enriclluelles/route_translator).
267
266
 
268
267
  ### Setting the Locale from the Client Supplied Information
269
268
 
@@ -289,7 +288,7 @@ private
289
288
  end
290
289
  ```
291
290
 
292
- Of course, in a production environment you would need much more robust code, and could use a plugin such as Iain Hecker's [http_accept_language](https://github.com/iain/http_accept_language/tree/master) or even Rack middleware such as Ryan Tomayko's [locale](https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb).
291
+ Of course, in a production environment you would need much more robust code, and could use a gem such as Iain Hecker's [http_accept_language](https://github.com/iain/http_accept_language/tree/master) or even Rack middleware such as Ryan Tomayko's [locale](https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb).
293
292
 
294
293
  #### Using GeoIP (or Similar) Database
295
294
 
@@ -370,7 +369,7 @@ NOTE: Rails adds a `t` (`translate`) helper method to your views so that you do
370
369
 
371
370
  So let's add the missing translations into the dictionary files (i.e. do the "localization" part):
372
371
 
373
- ```ruby
372
+ ```yaml
374
373
  # config/locales/en.yml
375
374
  en:
376
375
  hello_world: Hello world!
@@ -422,7 +421,7 @@ OK! Now let's add a timestamp to the view, so we can demo the **date/time locali
422
421
 
423
422
  And in our pirate translations file let's add a time format (it's already there in Rails' defaults for English):
424
423
 
425
- ```ruby
424
+ ```yaml
426
425
  # config/locales/pirate.yml
427
426
  pirate:
428
427
  time:
@@ -485,8 +484,6 @@ NOTE: The default locale loading mechanism in Rails does not load locale files i
485
484
 
486
485
  ```
487
486
 
488
- Do check the [Rails i18n Wiki](http://rails-i18n.org/wiki) for list of tools available for managing translations.
489
-
490
487
  Overview of the I18n API Features
491
488
  ---------------------------------
492
489
 
@@ -677,58 +674,25 @@ en:
677
674
  <div><%= t('title.html') %></div>
678
675
  ```
679
676
 
680
- NOTE: Automatic conversion to HTML safe translate text is only available from the `translate` view helper method.
681
-
682
- ![i18n demo html safe](images/i18n/demo_html_safe.png)
683
-
684
- How to Store your Custom Translations
685
- -------------------------------------
686
-
687
- The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and YAML format.[^2]
688
-
689
- For example a Ruby Hash providing translations can look like this:
677
+ Interpolation escapes as needed though. For example, given:
690
678
 
691
- ```ruby
692
- {
693
- pt: {
694
- foo: {
695
- bar: "baz"
696
- }
697
- }
698
- }
699
- ```
700
-
701
- The equivalent YAML file would look like this:
702
-
703
- ```ruby
704
- pt:
705
- foo:
706
- bar: baz
679
+ ```yaml
680
+ en:
681
+ welcome_html: "<b>Welcome %{username}!</b>"
707
682
  ```
708
683
 
709
- As you see, in both cases the top level key is the locale. `:foo` is a namespace key and `:bar` is the key for the translation "baz".
710
-
711
- Here is a "real" example from the Active Support `en.yml` translations YAML file:
684
+ you can safely pass the username as set by the user:
712
685
 
713
- ```ruby
714
- en:
715
- date:
716
- formats:
717
- default: "%Y-%m-%d"
718
- short: "%b %d"
719
- long: "%B %d, %Y"
686
+ ```erb
687
+ <%# This is safe, it is going to be escaped if needed. %>
688
+ <%= t('welcome_html', username: @current_user.username) %>
720
689
  ```
721
690
 
722
- So, all of the following equivalent lookups will return the `:short` date format `"%b %d"`:
691
+ Safe strings on the other hand are interpolated verbatim.
723
692
 
724
- ```ruby
725
- I18n.t 'date.formats.short'
726
- I18n.t 'formats.short', scope: :date
727
- I18n.t :short, scope: 'date.formats'
728
- I18n.t :short, scope: [:date, :formats]
729
- ```
693
+ NOTE: Automatic conversion to HTML safe translate text is only available from the `translate` view helper method.
730
694
 
731
- Generally we recommend using YAML as a format for storing translations. There are cases, though, where you want to store Ruby lambdas as part of your locale data, e.g. for special date formats.
695
+ ![i18n demo html safe](images/i18n/demo_html_safe.png)
732
696
 
733
697
  ### Translations for Active Record Models
734
698
 
@@ -736,7 +700,7 @@ You can use the methods `Model.model_name.human` and `Model.human_attribute_name
736
700
 
737
701
  For example when you add the following translations:
738
702
 
739
- ```ruby
703
+ ```yaml
740
704
  en:
741
705
  activerecord:
742
706
  models:
@@ -751,7 +715,7 @@ Then `User.model_name.human` will return "Dude" and `User.human_attribute_name("
751
715
 
752
716
  You can also set a plural form for model names, adding as following:
753
717
 
754
- ```ruby
718
+ ```yaml
755
719
  en:
756
720
  activerecord:
757
721
  models:
@@ -762,6 +726,19 @@ en:
762
726
 
763
727
  Then `User.model_name.human(count: 2)` will return "Dudes". With `count: 1` or without params will return "Dude".
764
728
 
729
+ In the event you need to access nested attributes within a given model, you should nest these under `model/attribute` at the model level of your translation file:
730
+
731
+ ```yaml
732
+ en:
733
+ activerecord:
734
+ attributes:
735
+ user/gender:
736
+ female: "Female"
737
+ male: "Male"
738
+ ```
739
+
740
+ Then `User.human_attribute_name("gender.female")` will return "Female".
741
+
765
742
  #### Error Message Scopes
766
743
 
767
744
  Active Record validation error messages can also be translated easily. Active Record gives you a couple of namespaces where you can place your message translations in order to provide different messages and translation for certain models, attributes, and/or validations. It also transparently takes single table inheritance into account.
@@ -830,7 +807,7 @@ So, for example, instead of the default error message `"cannot be blank"` you co
830
807
 
831
808
  | validation | with option | message | interpolation |
832
809
  | ------------ | ------------------------- | ------------------------- | ------------- |
833
- | confirmation | - | :confirmation | - |
810
+ | confirmation | - | :confirmation | attribute |
834
811
  | acceptance | - | :accepted | - |
835
812
  | presence | - | :blank | - |
836
813
  | absence | - | :present | - |
@@ -850,6 +827,7 @@ So, for example, instead of the default error message `"cannot be blank"` you co
850
827
  | numericality | :equal_to | :equal_to | count |
851
828
  | numericality | :less_than | :less_than | count |
852
829
  | numericality | :less_than_or_equal_to | :less_than_or_equal_to | count |
830
+ | numericality | :other_than | :other_than | count |
853
831
  | numericality | :only_integer | :not_an_integer | - |
854
832
  | numericality | :odd | :odd | - |
855
833
  | numericality | :even | :even | - |
@@ -897,6 +875,24 @@ en:
897
875
  subject: "Welcome to Rails Guides!"
898
876
  ```
899
877
 
878
+ To send parameters to interpolation use the `default_i18n_subject` method on the mailer.
879
+
880
+ ```ruby
881
+ # user_mailer.rb
882
+ class UserMailer < ActionMailer::Base
883
+ def welcome(user)
884
+ mail(to: user.email, subject: default_i18n_subject(user: user.name))
885
+ end
886
+ end
887
+ ```
888
+
889
+ ```yaml
890
+ en:
891
+ user_mailer:
892
+ welcome:
893
+ subject: "%{user}, welcome to Rails Guides!"
894
+ ```
895
+
900
896
  ### Overview of Other Built-In Methods that Provide I18n Support
901
897
 
902
898
  Rails uses fixed strings and other localizations, such as format strings and other format information in a couple of helpers. Here's a brief overview.
@@ -921,6 +917,55 @@ Rails uses fixed strings and other localizations, such as format strings and oth
921
917
 
922
918
  * `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#L33) scope.
923
919
 
920
+ How to Store your Custom Translations
921
+ -------------------------------------
922
+
923
+ The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and YAML format.[^2]
924
+
925
+ For example a Ruby Hash providing translations can look like this:
926
+
927
+ ```yaml
928
+ {
929
+ pt: {
930
+ foo: {
931
+ bar: "baz"
932
+ }
933
+ }
934
+ }
935
+ ```
936
+
937
+ The equivalent YAML file would look like this:
938
+
939
+ ```yaml
940
+ pt:
941
+ foo:
942
+ bar: baz
943
+ ```
944
+
945
+ As you see, in both cases the top level key is the locale. `:foo` is a namespace key and `:bar` is the key for the translation "baz".
946
+
947
+ Here is a "real" example from the Active Support `en.yml` translations YAML file:
948
+
949
+ ```yaml
950
+ en:
951
+ date:
952
+ formats:
953
+ default: "%Y-%m-%d"
954
+ short: "%b %d"
955
+ long: "%B %d, %Y"
956
+ ```
957
+
958
+ So, all of the following equivalent lookups will return the `:short` date format `"%b %d"`:
959
+
960
+ ```ruby
961
+ I18n.t 'date.formats.short'
962
+ I18n.t 'formats.short', scope: :date
963
+ I18n.t :short, scope: 'date.formats'
964
+ I18n.t :short, scope: [:date, :formats]
965
+ ```
966
+
967
+ Generally we recommend using YAML as a format for storing translations. There are cases, though, where you want to store Ruby lambdas as part of your locale data, e.g. for special date formats.
968
+
924
969
  Customize your I18n Setup
925
970
  -------------------------
926
971
 
@@ -1006,9 +1051,9 @@ If you find anything missing or wrong in this guide, please file a ticket on our
1006
1051
  Contributing to Rails I18n
1007
1052
  --------------------------
1008
1053
 
1009
- I18n support in Ruby on Rails was introduced in the release 2.2 and is still evolving. The project follows the good Ruby on Rails development tradition of evolving solutions in plugins and real applications first, and only then cherry-picking the best-of-breed of most widely useful features for inclusion in the core.
1054
+ I18n support in Ruby on Rails was introduced in the release 2.2 and is still evolving. The project follows the good Ruby on Rails development tradition of evolving solutions in gems and real applications first, and only then cherry-picking the best-of-breed of most widely useful features for inclusion in the core.
1010
1055
 
1011
- Thus we encourage everybody to experiment with new ideas and features in plugins or other libraries and make them available to the community. (Don't forget to announce your work on our [mailing list](http://groups.google.com/group/rails-i18n!))
1056
+ Thus we encourage everybody to experiment with new ideas and features in gems or other libraries and make them available to the community. (Don't forget to announce your work on our [mailing list](http://groups.google.com/group/rails-i18n!))
1012
1057
 
1013
1058
  If you find your own locale (language) missing from our [example translations data](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale) repository for Ruby on Rails, please [_fork_](https://github.com/guides/fork-a-project-and-submit-your-modifications) the repository, add your data and send a [pull request](https://github.com/guides/pull-requests).
1014
1059
 
@@ -1016,7 +1061,6 @@ If you find your own locale (language) missing from our [example translations da
1016
1061
  Resources
1017
1062
  ---------
1018
1063
 
1019
- * [rails-i18n.org](http://rails-i18n.org) - Homepage of the rails-i18n project. You can find lots of useful resources on the [wiki](http://rails-i18n.org/wiki).
1020
1064
  * [Google group: rails-i18n](http://groups.google.com/group/rails-i18n) - The project's mailing list.
1021
1065
  * [GitHub: rails-i18n](https://github.com/svenfuchs/rails-i18n/tree/master) - Code repository for the rails-i18n project. Most importantly you can find lots of [example translations](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale) for Rails that should work for your application in most cases.
1022
1066
  * [GitHub: i18n](https://github.com/svenfuchs/i18n/tree/master) - Code repository for the i18n gem.
@@ -9,6 +9,7 @@ Ruby on Rails Guides
9
9
  <% content_for :index_section do %>
10
10
  <div id="subCol">
11
11
  <dl>
12
+ <dt></dt>
12
13
  <dd class="kindle">Rails Guides are also available for <%= link_to 'Kindle', @mobi %>.</dd>
13
14
  <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
15
  </dl>