Search code examples
ruby-on-railstwitter-bootstrapdeviseflash-message

Dismiss Button in Ruby on Rails


i'm using bootstrap and Devise and trying to get a dismiss button on the Flash Messages. I tried a lot of different stuff but i'm not getting the button to appear right.

My Code for the moment is:

<% flash.each do |name, msg| %>
  <%= content_tag(:div, msg, class: "alert alert-#{name}") %>
<% end %>

Somewhere in there, somehow, i must add the dismiss button code from bootstrap which is:

<button type="button" class="close" data-dismiss="alert">&times;</button>

Solution

  • pass block to content_tag like this:

    <% flash.each do |name, msg| %>
     <%= content_tag(:div, class: "alert alert-#{name}") do%>
        <%=msg%>
        <button type="button" class="close" data-dismiss="alert">&times;</button>
     <%end%>
    
    <% end %>