why redirects from a null_session action wont supp

2019-07-25 18:53发布

问题:

I have an action which is actually used as a return-url from my payment gateway. So for making it work I set

  protect_from_forgery with: :null_session, only: [:verify_payment]

  def verify_payment
    data={}
    params.each do |name, value|
      data[name]=value
    end
    booking=Booking.find(params['booking'])
    if booking.charge_card(data)
      redirect_to booking_confirmation_path(booking: data["booking"]), success: "these wont show"
    else
      redirect_to booking_summary_path(booking_id: data["booking"]), error: "these wont show"
    end
  end

could some one tell me why the flash wont work on redirect?

flash.empty? will return true after redirect..why is that?

But if I render it will work..

回答1:

You can assign :notice, :alert or the general purpose :flash:

Try this.

redirect_to booking_confirmation_path(booking: data["booking"]),flash: {  success: "Your Success Message" }

redirect_to booking_summary_path(booking_id: data["booking"]), flash: { error: "Your Error Message" }

For more information refer this rails guide.