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无法完成消息传递。
-完-