Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method add_to_base

I'm working with activemerchant and it raise me this error when validating the card is this ok in rails 3? thank you in advance more power to all

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

it is pointing to Undefined method add_to_base

like image 256
Led Avatar asked Apr 23 '12 16:04

Led


3 Answers

add_to_base method was removed from rails 3. You should use errors[:base] << "error" instead.

like image 182
Vasiliy Ermolovich Avatar answered Nov 18 '22 13:11

Vasiliy Ermolovich


I prefer the following, over the accepted answer:

errors.add :base, 'error message'

like image 37
Brad Werth Avatar answered Nov 18 '22 12:11

Brad Werth


In your model just make:

:add_to_base=> false

Access it in your controller as:

model_instance.errors.messages
like image 2
user1540205 Avatar answered Nov 18 '22 13:11

user1540205