diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-02 20:53:12 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-02 20:53:12 -0500 |
commit | 79f06a91345a301e1a2f2378552b5860a493b256 (patch) | |
tree | 54c8b48870d09a3780ab389f09025925c0c85313 /guides/source/i18n.md | |
parent | 5aa4157ae44112f61ef923cab33fa1e0aa381e41 (diff) | |
parent | 3f70c69437531e975838d1788b13570972453113 (diff) | |
download | rails-79f06a91345a301e1a2f2378552b5860a493b256.tar.gz rails-79f06a91345a301e1a2f2378552b5860a493b256.tar.bz2 rails-79f06a91345a301e1a2f2378552b5860a493b256.zip |
Merge pull request #14564 from killthekitten/patch-2
Fix default_url_options example in i18n guide
Diffstat (limited to 'guides/source/i18n.md')
-rw-r--r-- | guides/source/i18n.md | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/guides/source/i18n.md b/guides/source/i18n.md index bef738b75b..6bd033f0de 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -212,17 +212,16 @@ The most usual way of setting (and passing) the locale would be to include it in 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. -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. +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. -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). +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). We can include something like this in our `ApplicationController` then: ```ruby # app/controllers/application_controller.rb -def default_url_options(options={}) - logger.debug "default_url_options is passed options: #{options.inspect}\n" - { locale: I18n.locale } +def default_url_options(options = {}) + { locale: I18n.locale }.merge options end ``` |