user2049259 user2049259 - 5 months ago 19
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 %>

LHH LHH
Answer

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

Comments