user2049259 user2049259 - 1 year ago 107
Ruby Question

For rails app, how to show multiple flash[:notice] in html?

This is what I wrote in a controller file, but only 1 notice (the last one) would appear.

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

I want to show all of the three notice together (at one time), is there anyway to achieve this?

in my html:

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

Answer Source

You could try like this

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

And then in your views, output it as

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

or whatever you want in your view

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download