gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:52:26 25 4
gpt4 key购买 nike

我写了下面的代码来显示 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com