File: //usr/local/rvm/gems/default/doc/activerecord-6.1.4.1/ri/ActiveRecord/Integration/to_param-i.ri
U:RDoc::AnyMethod[iI"
to_param:ETI"'ActiveRecord::Integration#to_param;TF:publico:RDoc::Markup::Document:@parts[
o:RDoc::Markup::Paragraph; [I"OReturns a +String+, which Action Pack uses for constructing a URL to this ;TI"Pobject. The default implementation returns this record's id as a +String+, ;TI"'or +nil+ if this record's unsaved.;To:RDoc::Markup::BlankLine o;
; [I"JFor example, suppose that you have a User model, and that you have a ;TI"A<tt>resources :users</tt> route. Normally, +user_path+ will ;TI"8construct a path with the user object's 'id' in it:;T@o:RDoc::Markup::Verbatim; [I"*user = User.find_by(name: 'Phusion')
;TI"&user_path(user) # => "/users/1"
;T:@format0o;
; [I"MYou can override +to_param+ in your model to make +user_path+ construct ;TI";a path using the user's name instead of the user's id:;T@o;; [
I"%class User < ActiveRecord::Base
;TI"" def to_param # overridden
;TI" name
;TI" end
;TI" end
;TI"
;TI"*user = User.find_by(name: 'Phusion')
;TI"+user_path(user) # => "/users/Phusion";T;
0:
@fileI"%lib/active_record/integration.rb;T:0@omit_headings_from_table_of_contents_below000[ I"();T@(FI"Integration;TcRDoc::NormalModule00