开发者

rails 3 + jquery + ajax - dont discard flash upon ajax request which redirects

开发者 https://www.devze.com 2023-03-16 01:26 出处:网络
Normally, I call flash.discard if my request is xhr. I do this as an after filter in the application controller.

Normally, I call flash.discard if my request is xhr. I do this as an after filter in the application controller.

However开发者_如何学Go, I dont want to call flash.discard in the event that I have an ajax call which sets a flash and then redirects to another page.

How do I achieve this?


If I understood it right, you need to know if a response is a redirect. Create an after filter in application controller to check the response status.

after_filter :discard_flash_message

def discard_flash_message
  if request.xhr? and response.status == :found
    //do not call flash.discard
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消