aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2015-08-01 23:08:53 +0900
committeryui-knk <spiketeika@gmail.com>2015-08-01 23:08:53 +0900
commit2ea95a522a058183c27552d78722ed52716b3b13 (patch)
tree55656812e5103756eb3060e3948d7e5ba3a6da26 /guides
parentd1cdf52db608ad53b676581f9482e100d4be35bd (diff)
downloadrails-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 'guides')
-rw-r--r--guides/source/routing.md14
1 files changed, 14 insertions, 0 deletions
diff --git a/guides/source/routing.md b/guides/source/routing.md
index 52f11f92bd..02763eabcd 100644
--- a/guides/source/routing.md
+++ b/guides/source/routing.md
@@ -1087,6 +1087,20 @@ edit_videos GET /videos/:identifier/edit(.:format) videos#edit
Video.find_by(identifier: params[:identifier])
```
+You can override `ActiveRecord::Base#to_param` of a related
+model to constructe an URL.
+
+```ruby
+class Video < ActiveRecord::Base
+ def to_param # overridden
+ identifier
+ end
+end
+
+video = Video.find_by(identifier: "Roman-Holiday")
+edit_videos_path(video) # => "/videos/Roman-Holiday"
+```
+
Inspecting and Testing Routes
-----------------------------