Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 %>
like image 634
user2049259 Avatar asked Dec 15 '22 23:12

user2049259


1 Answers

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

like image 169
LHH Avatar answered Jan 28 '23 15:01

LHH