Search code examples
ruby-on-railsactivemerchantmass-assignment

ActiveMerchant purchase function rails 3.2.5 mass-assign


I am using Rails 3.2.5. Following Ryan Bates tutorial.

http://railscasts.com/episodes/145-integrating-active-merchant. My order.rb has this function

  def purchase
    response = GATEWAY.purchase(price_in_cents, credit_card, purchase_options)
    transactions.create!(:action => "purchase", :amount => price_in_cents, :response => response)
    cart.update_attribute(:purchased_at, Time.now) if response.success?
    response.success?
  end

Since rails 3.2.5 uses MassAssignmentSecurity.I get the following error.

Can't mass-assign protected attributes: action, amount, response

I have tried adding them to the attr_accessible list but no luck. How do i add them to the list or at-least override them?


Solution

  • Please take a look on this previous topic: "WARNING: Can't mass-assign protected attributes"

    I believe it will help you...