gpt4 book ai didi

ruby-on-rails - Rails 3 ActiveMerchant 信用卡未验证

转载 作者:太空宇宙 更新时间:2023-11-03 16:34:49 26 4
gpt4 key购买 nike

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

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

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'

谢谢:)

最佳答案

Can't mass-assign protected attributes: card_number, card_verification

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

关于ruby-on-rails - Rails 3 ActiveMerchant 信用卡未验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16825330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com