gpt4 book ai didi

ruby-on-rails - 对于 Rails 应用程序,如何显示多个 flash[ :notice] in html?

转载 作者:数据小太阳 更新时间:2023-10-29 07:22:29 24 4
gpt4 key购买 nike

这是我在 Controller 文件中写的内容,但只会出现 1 个通知(最后一个)。

flash[:notice] ="a: " + aa.to_s
flash[:notice] ="b: " + bb.to_s
flash[:notice] ="c: " + cc.to_s

我想同时显示所有三个通知(一次),有什么方法可以实现吗?

在我的 html 中:

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

最佳答案

你可以这样试试

flash[:notice] = ["a: " + aa.to_s]
flash[:notice] << "b: " + bb.to_s
flash[:notice] << "c: " + cc.to_s

然后在你的 View 中,输出为

<%= flash[:notice].join("<br>") %>

或者你想要的任何东西

关于ruby-on-rails - 对于 Rails 应用程序,如何显示多个 flash[ :notice] in html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23321623/

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