instance method
to_param
Ruby on Rails 6.1.7.10
Since v3.0.20Signature
to_param()
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"
Source
# File activemodel/lib/active_model/conversion.rb, line 82
def to_param
(persisted? && key = to_key) ? key.join("-") : nil
end
Defined in activemodel/lib/active_model/conversion.rb line 82
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Conversion