0

I cannot seem to get the card validating at all. Please help me!

The error I get when submitting a blank order form.

ActiveModel::MassAssignmentSecurity::Error in OrdersController#create
Can't mass-assign protected attributes: card_number, card_verification

in order.rb

  attr_accessor :card_number, :card_verification
  attr_accessible :card_expires_on, :card_type, :cart_id, :first_name, :ip_address, :last_name
  belongs_to :cart

  validate :validate_card, :on => :create
  validate :validate_card, :on => :update

I obviously do not want to store card_number and card_verification in the database.

The methods in order.rb

  def validate_card
      credit_card.errors.full_messages.each {|msg| errors[:base] << msg} if credit_card.invalid?

    end

    def credit_card
        @credit_card ||= ActiveMerchant::Billing::CreditCard.new(
            :type                       => card_type,
            :number             => card_number,
            :verification_value => card_verification,
            :month                  => card_expires_on.try(:month),
            :year                       => card_expires_on.try(:year),
            :first_name         => first_name,
            :last_name          => last_name
            )
    end

Please try and help!

If this helps I have this in the Gemfile

gem 'activemerchant'

Thanks :)

4

1 回答 1

1

无法批量分配受保护的属性:card_number、card_verification

将这些属性 ( :card_number, :card_verification) 添加到attr_accessible列表中。验证甚至还没有开始,它是 ActiveRecord 试图从params.

于 2013-05-29T23:58:04.857 回答