forked from heartcombo/simple_form
-
Notifications
You must be signed in to change notification settings - Fork 0
Use with ActiveModel compliant models
dnagir edited this page Sep 19, 2012
·
2 revisions
SimpleForm can also be used with any ActiveModel-compliant objects
(such as created using ActiveAttr).
The only thing you have to keep in mind is to define <attribute>_attributes= setter for the nested models.
This is only required for non-ActiveRecord models where accepts_nested_attributes_for is used instead.
See the Rails' fields_for for more information.
It is also possible to "mix and match" different types of models (such as ActiveRecord and poor ActiveModel ones).
For example:
class ReservationFee < ActiveRecord::Base
attr_accessor :credit_card
# This is required by SimpleForm and Rails for non-ActiveRecord nested attributes
def credit_card_attributes=(attributes)
@credit_card = CreditCard.new(attributes)
end
end
class CreditCard
include ActiveAttr::Model
attribute :number
attribute :expiry
attribute :cvn
attribute :name
endProvided that you have it, SimpleForm can be used to generate nested models.