diff options
author | yui-knk <spiketeika@gmail.com> | 2015-08-01 23:08:53 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2015-08-01 23:08:53 +0900 |
commit | 2ea95a522a058183c27552d78722ed52716b3b13 (patch) | |
tree | 55656812e5103756eb3060e3948d7e5ba3a6da26 /actionpack/lib/action_dispatch | |
parent | d1cdf52db608ad53b676581f9482e100d4be35bd (diff) | |
download | rails-2ea95a522a058183c27552d78722ed52716b3b13.tar.gz rails-2ea95a522a058183c27552d78722ed52716b3b13.tar.bz2 rails-2ea95a522a058183c27552d78722ed52716b3b13.zip |
[ci skip]
Add descriptions about `ActiveRecord::Base#to_param` to
* `ActionDispatch::Routing::Base#match`
* Overriding Named Route Parameters (guide)
When passes `:param` to route definision, always `to_param` method of
related model is overridden to constructe an URL by passing these
model instance to named_helper.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ec530c6e8a..64352d5742 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -443,6 +443,21 @@ module ActionDispatch # dynamic segment used to generate the routes). # You can access that segment from your controller using # <tt>params[<:param>]</tt>. + # In your router: + # + # resources :user, param: :name + # + # You can override <tt>ActiveRecord::Base#to_param</tt> of a related + # model to constructe an URL. + # + # class User < ActiveRecord::Base + # def to_param # overridden + # name + # end + # end + # + # user = User.find_by(name: 'Phusion') + # user_path(user) # => "/users/Phusion" # # [:path] # The path prefix for the routes. |