why redirects from a null_session action wont support flash in rails

牧云@^-^@ 提交于 2019-12-24 09:30:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!