问题
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.
来源:https://stackoverflow.com/questions/42013906/why-redirects-from-a-null-session-action-wont-support-flash-in-rails