【问题标题】:Rails 3 ActiveMerchant credit card not validatingRails 3 ActiveMerchant 信用卡未验证
【发布时间】:2013-05-25 09:19:51
【问题描述】:

我似乎根本无法验证卡。请帮帮我!

我在提交空白订单时遇到的错误。

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

按顺序.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'

谢谢:)

【问题讨论】:

    标签: ruby-on-rails ruby paypal activemerchant


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢。现在它不验证任何东西,它接受任何作为信用卡号传递的验证通过。啊,请帮忙! :(
    猜你喜欢
    • 2012-08-07
    • 2011-07-03
    • 2014-08-14
    • 2010-10-05
    • 2018-04-23
    • 2014-12-30
    • 1970-01-01
    • 2013-02-23
    • 2011-01-24
    相关资源
    最近更新 更多