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 :)