【发布时间】:2013-09-01 16:10:47
【问题描述】:
我使用的是activemodel(不是activerecord,我有以下代码:
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
但是当我尝试验证表单时,我在日期上收到以下 rails 错误:
undefined method `dob(3i)=' for #<PaymentForm:0x007fe0379c3668>
如何让activemodel自动将dob元素转换成dob变量?
【问题讨论】:
-
不确定
dob是什么? -
这是如何工作的?
dob(3i) -
我也有同样的问题,以防你找到答案。
-
不,我想我没有找到答案,我转而使用活动记录。
-
@phil88530 你找到答案了吗?
标签: ruby-on-rails ruby validation date activemodel