From 2ea95a522a058183c27552d78722ed52716b3b13 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Sat, 1 Aug 2015 23:08:53 +0900 Subject: [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. --- actionpack/lib/action_dispatch/routing/mapper.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') 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 # params[<:param>]. + # In your router: + # + # resources :user, param: :name + # + # You can override ActiveRecord::Base#to_param 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. -- cgit v1.2.3