Method: ActiveModel::Conversion#to_param

Defined in:
activemodel/lib/active_model/conversion.rb

#to_paramObject

Returns a string representing the object’s key suitable for use in URLs, or nil if persisted? is false.

class Person
  include ActiveModel::Conversion
  attr_accessor :id

  def initialize(id)
    @id = id
  end

  def persisted?
    true
  end
end

person = Person.new(1)
person.to_param # => "1"


90
91
92
# File 'activemodel/lib/active_model/conversion.rb', line 90

def to_param
  (persisted? && (key = to_key) && key.all?) ? key.join(self.class.param_delimiter) : nil
end