diff options
author | Richard Schneeman <richard.schneeman@gmail.com> | 2015-08-01 09:42:31 -0500 |
---|---|---|
committer | Richard Schneeman <richard.schneeman@gmail.com> | 2015-08-01 09:42:31 -0500 |
commit | c7a9f572d16b742b0138fb658bae30f08509b584 (patch) | |
tree | 58843200913e84793e9d176912726a6c50188127 /guides/source | |
parent | 21b870c906ee23ea3f8055e66aa16476f5369055 (diff) | |
parent | 2ea95a522a058183c27552d78722ed52716b3b13 (diff) | |
download | rails-c7a9f572d16b742b0138fb658bae30f08509b584.tar.gz rails-c7a9f572d16b742b0138fb658bae30f08509b584.tar.bz2 rails-c7a9f572d16b742b0138fb658bae30f08509b584.zip |
Merge pull request #21088 from yui-knk/doc/to_param
[ci skip]
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/routing.md | 14 |
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 ----------------------------- |