I am using activemodel(Not activerecord, and I have the following code:
class PaymentForm
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :agree_auto_renew, :card_owner, :address1, :address2, :address3, :address4, :postcode,
:firstname, :surname, :dob, :email, :email_confirmation
validates_presence_of :agree_auto_renew, :card_owner, :address1, :address2, :address3, :address4, :postcode
validates_presence_of :firstname, :surname, :email, :email_confirmation, :if => :not_owner
validates_date :dob, :if => :not_owner
validates_confirmation_of :email, :if => :not_owner
private
def initialize
@errors = ActiveModel::Errors.new(self)
end
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def not_owner
! self.card_owner
end
def persisted?
false
end
end
But when I try to validate the form, I got the following rails error on dates:
undefined method `dob(3i)=' for #<PaymentForm:0x007fe0379c3668>
How can I make activemodel auto convert dob elements into the dob variable?