Kermit
Kermit

Reputation: 5992

Rails html_safe notice when redirecting

I'm trying to add icons to my notices in order to make them a little more human. However, the browser renders it as plaintext. I suspect that this has something to do with Rack and flash messages.

Here is the code in my controller:

redirect_to billing_index_path, 
  notice: "<i class='lnr lnr-checkmark-circle'></i> Payment method updated successfully!".html_safe

I've also tried notice:("my_string").html_safe and raw doesn't work with strings notice:("my_string").raw

Question -- How can I get my string to render as html?

Upvotes: 0

Views: 210

Answers (1)

MZaragoza
MZaragoza

Reputation: 10111

I have done this in the past. I moved my raw or html_safe to the view

<% if flash[:notice].present? %>
  <div class='alert alert-info'>
    <%= raw flash[:notice] %>
  </div>
<% end %>

I hope that this helps :)

Upvotes: 2

Related Questions