Ruby on rails 在Rails中呈现操作时未显示警报
我编写了以下代码以显示带有警报闪光消息的Ruby on rails 在Rails中呈现操作时未显示警报,ruby-on-rails,ruby-on-rails-3,controller,ruby-on-rails-3.2,alert,Ruby On Rails,Ruby On Rails 3,Controller,Ruby On Rails 3.2,Alert,我编写了以下代码以显示带有警报闪光消息的show.html.erb视图: render action: 'show', alert: 'Please fix mistakes outlined in red' 但是,警报不会出现。不过还是有一些通知。我假设我的渲染操作:上面的“show”调用是错误的,因为我只是凭直觉写的。这是我的html.erb代码: <%if notice%><p id="notice"><%= notice %></p>&l
show.html.erb
视图:
render action: 'show', alert: 'Please fix mistakes outlined in red'
但是,警报不会出现。不过还是有一些通知。我假设我的渲染操作:上面的“show”
调用是错误的,因为我只是凭直觉写的。这是我的html.erb代码:
<%if notice%><p id="notice"><%= notice %></p><%end%>
<%if alert%><p id="alert"><%= alert %></p><%end%>
处理闪烁的更标准方法是在视图布局中编写以下内容
<% flash.each do |key, value| %>
<p class="alert alert-<%= key %>"><%= value %></p>
<% end %>
是否从控制器操作调用“渲染”?将
flash[:alert]
设置为“我的字符串”效果很好。因此我猜render
方法不像redirect\u to
方法那样接受警报
散列条目。为什么闪存。每个机制都高于标准?Rails的脚手架机制具有id=“notice”
消息,Desive具有id=“notice”
和id=“alert”
通知机制。
flash[:alert] = 'Please fix mistakes outlined in red'
render 'show'