slh*_*hck 2 ruby ruby-on-rails
我在控制器中有一行,它将使用自定义Flash消息重定向到主屏幕,如下所示:
redirect_to :controller => :home, :action => :index, :alert => "You are not yet assigned to an experiment." and return
Run Code Online (Sandbox Code Playgroud)
然后,用户将重定向到以下页面: http://localhost:3000/home?alert=You+are+not+yet+assigned+to+an+experiment
但是,尽管所有其他Flash消息都在我的应用程序中工作,但未显示flash消息.的意见/布局/ application.html.erb文件包含以下内容:
<div class="flash">
<%- if !notice.nil? -%>
<p class="notice"><%= notice %></p>
<%- end -%>
<%- if !alert.nil? -%>
<p class="alert"><%= alert %></p>
<%- end -%>
</div>
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
Flash正在使用会话来存储消息
flash[:alert] = "You are not yet assigned to an experiment."
redirect_to :controller => :home, :action => :index and return
<%= flash[:alert] %>
Run Code Online (Sandbox Code Playgroud)
如果你想通过参数传递它,你应该使用params [:param_name]
redirect_to :controller => :home, :action => :index, :alert => "You are not yet assigned to an experiment." and return
<%= params[:alert] %>
Run Code Online (Sandbox Code Playgroud)
Flash更为可取,它可以跨页面隐式工作,并在显示后清除
| 归档时间: |
|
| 查看次数: |
7240 次 |
| 最近记录: |