Type:
Module

Active Model Conversion

Handles default conversions: #to_model, #to_key, #to_param, and to_partial_path.

Let's take for example this non-persisted object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class ContactMessage
  include ActiveModel::Conversion
 
  # ContactMessage are never persisted in the DB
  def persisted?
    false
  end
end
 
cm = ContactMessage.new
cm.to_model == cm  # => true
cm.to_key          # => nil
cm.to_param        # => nil
cm.to_partial_path # => "contact_messages/contact_message"
to_key
  • References/Ruby on Rails/Rails/Classes/ActiveModel/ActiveModel::Conversion

to_key() Instance Public methods Returns an

2025-01-10 15:47:30
to_partial_path
  • References/Ruby on Rails/Rails/Classes/ActiveModel/ActiveModel::Conversion

to_partial_path() Instance Public methods Returns a string identifying

2025-01-10 15:47:30
to_param
  • References/Ruby on Rails/Rails/Classes/ActiveModel/ActiveModel::Conversion

to_param() Instance Public methods Returns a string representing

2025-01-10 15:47:30
to_model
  • References/Ruby on Rails/Rails/Classes/ActiveModel/ActiveModel::Conversion

to_model() Instance Public methods If your object is already designed to implement

2025-01-10 15:47:30