`
minixx77
  • 浏览: 10431 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
社区版块
存档分类
最新评论

rails中flash[:notice]的问题

阅读更多
问题:在action1中设置了flash[:notice]值,当点击一个链接跳到另外一个action2的时候,flash[:notice]还会显示,只有再次点击其它的链接,flash[:notice]才会消失。
原因:flash[:notice] is meant only for redirect action, because the message is only cleared after at the end of redirected view request. So if you don’t redirect the request, and you click on the next request, that message will still be displayed.


解决方法:But sometimes, we just want to display custom error messages only for current request without the redirection (esp. for non-ActiveRecord error messages). So the option is to use flash.now[:notice]. It clears the flash message at the end of current request (without redirection)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics