flash[:notice] 不适用于 redirect_to [英] flash[:notice] doesn't work with redirect_to
本文介绍了flash[:notice] 不适用于 redirect_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用控制器状态:
flash[:notice] = 'message'重定向到(控制器:'项目',动作:'列表')
我不知道为什么通知没有出现.
我尝试并检查了很多东西:
flash.keep
flash.keep[:notice] = 'message'
flash[:notice]
与render
配合良好redirect_to(controller: 'item', action: 'list', notice: 'message')
flash.now[:notice] = "Hello world"
flash.now['foo'] = "Hello world"
带有<%= flash['foo'] %>
在视图中- 布局中有一个 <%= flash[:notice] %>
我将以下代码放入布局中.当我的控制器方法有一个同名的视图时,flash[:notice] 工作正常.当我尝试访问另一个没有视图的控制器时会出现问题.
<% if !flash[:notice].blank?%><div class="通知"><%= flash[:notice]%>
<%结束%><% if !flash[:alert].blank?%><div class="alert"><%= flash[:alert]%>
<%结束%>
有人可以帮忙吗?
信息:
- Ruby (2.0.0)
- Rails (3.2.13)
解决方案
我不知道发生了什么.
我更新到 ruby 2.0.0,它又开始工作了...
I'm using from controller status:
flash[:notice] = 'message'
redirect_to(controller: 'item', action: 'list')
I don't know why the notice don't show up.
I tried and checked many things:
flash.keep
flash.keep[:notice] = 'message'
flash[:notice]
works fine withrender
redirect_to(controller: 'item', action: 'list', notice: 'message')
flash.now[:notice] = "Hello world"
flash.now['foo'] = "Hello world"
with<%= flash['foo'] %>
in the view- There is a <%= flash[:notice] %> in the layout
I put the following code to in the layout. flash[:notice] work fine when I the controller method have a view with the same name. The problem happens when I try to reach another controller which don't have a view.
<% if !flash[:notice].blank? %>
<div class="notice">
<%= flash[:notice] %>
</div>
<% end %>
<% if !flash[:alert].blank? %>
<div class="alert">
<%= flash[:alert] %>
</div>
<% end %>
Can anyone help?
Info:
- Ruby (2.0.0)
- Rails (3.2.13)
解决方案
I have no idea about what happened.
I updated to ruby 2.0.0 and it just started to work again...
这篇关于flash[:notice] 不适用于 redirect_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文