Ryan Drake
Ryan Drake

Reputation: 643

Rails 4: Error messages not displaying with Bootstrap classes

In my application.html.erb file, I have:

<div class="container">
  <% flash.each do | type, message | %>
  <div class="alert <%= flash_class(type) %>">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span></button>
      <%= message %>
  </div>
  <% end %>

  <%= yield %>
</div>

I have the flash_class as a helper method:

module ApplicationHelper
  def flash_class(type)
    case type
    when :alert
     "alert-error"
    when :notice
     "alert-success"
    else
     ""
    end
  end
end

Though what happens is the class isn't being appended in the HTML. When I create an error, the 'alert-error' class isn't added on:

enter image description here

Any ideas why that might be the case?

Upvotes: 0

Views: 75

Answers (1)

bsvin33t
bsvin33t

Reputation: 648

You might be sending in String for type instead of Symbol in the flash_class method.

An easy fix would be calling type.to_sym in the flash_class helper method.

Upvotes: 1

Related Questions