未定义的方法add_to_base

我正在使用activemerchant并且在validation卡在轨道3中是否正常时它会引发我的错误? 先谢谢你们所有人的力量

belongs_to :reservation attr_accessor :card_number, :card_verification validate :validate_card, :on => :create def validate_card unless credit_card.valid? credit_card.errors.full_messages.each do |message| errors.add_to_base "error" end end end def credit_card @credit_card ||= ActiveMerchant::Billing::CreditCard.new( :type => card_type, :number => card_number, :verification_value => card_verification, :month => card_expires_on.month, :year => card_expires_on.year, :first_name => first_name, :last_name => last_name ) end 

它指向Undefined method add_to_base

add_to_base方法已从rails 3中删除。您应该使用errors[:base] << "error"来代替。

在接受的答案中,我更喜欢以下内容:

errors.add :base, 'error message'

在您的模型中,只需:

 :add_to_base=> false 

在控制器中访问它:

 model_instance.errors.messages