Search code examples
ruby-on-railsruby-on-rails-4noticeflash-message

Flash[:notice] multi-lines and single line


i want to pass to flash[:notice] an Array of string and a single String (in two different times)

example:

multi_lines << "Product: #{product.title} disponibile in #{product_quantity}<br/>"
multi_lines << "Product: #{product.title} disponibile in #{product_quantity}<br/>"
notice: multi_lines

And

single_text = "Hello"
notice: single_text

I have in my view the following code:

<% if notice %>
<p id= "notice"><%= notice.join("<br/>").html_safe %></p>
<% end %>

Of corse , when i pass the single string Rails say me that the join method doesn't exist in the String class. How can overpass the error?

Thanky


Solution

  • Should work.

    single_text = ["Hello"]
    notice: single_text
    

    or perhaps simpler

    single_text = "Hello"
    notice: Array.new(1, single_text)