Rails 3 ActiveMerchant信用卡未验证

时间:2013-05-29 23:01:11

标签: ruby-on-rails ruby paypal activemerchant

我似乎无法对卡进行验证。请帮帮我!

提交空白订单时出现的错误。

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

我显然不想将card_number和card_verification存储在数据库中。

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

请尝试帮助!

如果这有助于我在Gemfile中有这个

gem 'activemerchant'

谢谢:)

1 个答案:

答案 0 :(得分:1)

  

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

将这些属性(:card_number:card_verification)添加到attr_accessible列表中。验证甚至没有启动,它是ActiveRecord尝试从params创建您的对象。