Ruby on rails 未显示Rails闪存消息
我在控制器中有一行代码,它将重定向到主屏幕,并显示一条自定义的flash消息,如下所示:Ruby on rails 未显示Rails闪存消息,ruby-on-rails,ruby,Ruby On Rails,Ruby,我在控制器中有一行代码,它将重定向到主屏幕,并显示一条自定义的flash消息,如下所示: redirect_to :controller => :home, :action => :index, :alert => "You are not yet assigned to an experiment." and return 然后将用户重定向到以下页面:http://localhost:3000/home?alert=You+是否+尚未+分配+到+实验 但是,虽然所有其他fl
redirect_to :controller => :home, :action => :index, :alert => "You are not yet assigned to an experiment." and return
然后将用户重定向到以下页面:http://localhost:3000/home?alert=You+是否+尚未+分配+到+实验
但是,虽然所有其他flash消息都在我的应用程序中工作,但不会显示flash消息。views/layouts/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>
我做错了什么?在您看来,您可以使用
<%= flash[:notice] %>
一定是
redirect_to({ :controller => :home, :action => :index }, :alert => "You are not yet assigned to an experiment.")
Flash正在使用会话来存储消息
flash[:alert] = "You are not yet assigned to an experiment."
redirect_to :controller => :home, :action => :index and return
<%= flash[:alert] %>
flash[:alert]=“您尚未分配到实验。”
重定向到:controller=>:home,:action=>:index并返回
如果要通过params传递,应使用params[:param_name]
redirect_to :controller => :home, :action => :index, :alert => "You are not yet assigned to an experiment." and return
<%= params[:alert] %>
重定向到:controller=>:home,:action=>:index,:alert=>“您还没有被分配到实验。”然后返回
Flash更可取,它可以隐式地跨页面工作,并且在显示后被清除,如果我将
更改为
(以及If
子句),仍然不会显示任何消息。谢谢,这正是我所需要的!
flash[:alert] = "You are not yet assigned to an experiment."
redirect_to :controller => :home, :action => :index and return
<%= flash[:alert] %>
redirect_to :controller => :home, :action => :index, :alert => "You are not yet assigned to an experiment." and return
<%= params[:alert] %>