lazybios

flash[:notice]与flash.now[:notice]区别

Rails中通过flash可以在http跳转中方便的传递消息对象(该消息只能维持到下次http跳转),常用有两种

flash[:notice] = "notice message"
redirecr_to other_path

但上面的调用方法只能在两个不同的actiion里通过调用redirect_to生效,想要在同一个action里传递,需要使用flash.now方法,见下

flash.now[:notice] = "notice message"
render :other

注意使用falsh.now不能用redirect_to做跳转,否则falsh无法完成消息传递。

-完-

微信关注「日拱一卒」公众号