ruby-on-rails - 在 Rails 中呈现 Action 时不显示警报

标签 ruby-on-rails ruby-on-rails-3 controller ruby-on-rails-3.2 alert

我写了下面的代码来显示 show.html.erb View 和一个警告闪现消息:

render action: 'show', alert: 'Please fix mistakes outlined in red'

但是,警报不会出现。虽然出现了通知。我假设上面的 render action: 'show' 调用是错误的,因为我只是凭直觉写的。这是我的 html.erb 代码:

<%if notice%><p id="notice"><%= notice %></p><%end%>
<%if alert%><p id="alert"><%= alert %></p><%end%>

最佳答案

一个更标准的处理闪烁的方法是在你的 View 布局中写下下面的内容

<% flash.each do |key, value| %>
    <p class="alert alert-<%= key %>"><%= value %></p>
<% end %>

并在你的 Controller 中写入以下内容

flash[:alert] = 'Please fix mistakes outlined in red'
render 'show'

关于ruby-on-rails - 在 Rails 中呈现 Action 时不显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12505073/

相关文章:

javascript - rails : Remote form in popup window not calling controller action

jquery - 动态添加内容的事件绑定(bind)遇到问题

ruby-on-rails - Rails - 如何在模型中获取完整的 URL

ruby-on-rails - rails : Validate unique combination of 3 columns

ruby - 使用 Ancestry gem 为对象提供多个父对象

ruby-on-rails - rails : Prevent duplicate inserts due to pressing back button and save again

java - 由 ModelAttribute 注释的多个方法。如何设置方法的调用顺序

ruby-on-rails - Rails 迁移不同的数据库

ruby-on-rails - Rails 中的大小写不敏感

c# - 无法将类型 'System.Linq.IQueryable<int>' 转换为 'int'