【发布时间】: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