Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a line break in a flash notice rails controller

I need to add a line break into a flash notice. So far I have this

flash[:success] = "We will notify you when we go LIVE! #{<br />} Meantime, complete this quick survey so we can get to know your interest.

But it is incorrect. Does anyone know how to properly do this in the controller?

I am using ruby 2.2.1p85 & Rails 4.0.10

like image 878
SupremeA Avatar asked Aug 30 '25 15:08

SupremeA


2 Answers

There is always a dirty way to do stuff in programming. Here you can create multi line array inside flash.

     flash[:success] = []
     flash[:success] = flash[:success] << "We will notify you when we go LIVE! "
     flash[:success] = flash[:success] << "Meantime, complete this quick survey so we can get to know your interest."

and display it like this

<% flash.each do |key, value| %>
  <% value.each do |text| %>
    <%= content_tag :div, text %>
  <% end %>
<% end %>   

This will definitely work.

But the best way to do that is this

flash[:success] = "We will notify you when we go LIVE! <br> Meantime, complete this quick survey so we can get to know your interest.".html_safe

If this also doesn't work then try it another way

in controller set

flash[:success] = "We will notify you when we go LIVE! <br> Meantime, complete this quick survey so we can get to know your interest."  

and in view display like

 <% flash.each do | value| %>
    <%= content_tag :div, value.html_safe %>
 <% end %> 
like image 148
Jitendar Avatar answered Sep 02 '25 21:09

Jitendar


flash[:success] = "We will notify you when we go LIVE! <br> Meantime, complete this quick survey so we can get to know your interest."
redirect_to YOUR_URL, flash: { html_safe: true }
like image 29
Imre Raudsepp Avatar answered Sep 02 '25 23:09

Imre Raudsepp