Question

I'm pretty close to implementing stripe on my web app using Rails 4, but I keep getting the following error:

ActiveModel::ForbiddenAttributesError in PaymentsController#create

The model calls out an issue at this line in my Payments Controller:

 params[:payment][:stripe_token] = charge.id
      @payment = Payment.new(params[:payment])

      respond_to do |format|
        if @payment.save

I figured the issue had to do with strong parameters so I tried adding the following to the bottom of my Payments Controller and I got nothing.

def payment_params
  params.require(:payment).permit(:payment, :stripe_token)
end

Thoughts on how to fix this. I was using the following tutorial to implement stripe payments, and it seems to work except for the error when I submit the form as my stripe test page shows the charges.

Website link: synaptian

Github of app: stripe_example

Any help would be appreciated.

Was it helpful?

Solution

It should be like this

payment_params[:stripe_token] = charge.id
  @payment = Payment.new(payment_params)

  respond_to do |format|
    if @payment.save

And you will have this method private in controller

private
 def payment_params
   params.require(:payment).permit(:payment, :stripe_token)
 end

Please refers rails 4 strong parameter tutorial if you are not aware of it. you can do it with simple. dont worry.

http://blog.sensible.io/2013/08/17/strong-parameters-by-example.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top