0

if i am using the devise gem with rails, how do i make the flash messages appear only when theres content inside of it.

does rails have an easy way to do this or do i manually need to do it in jquery?

currently im using twitter bootstrap v2 and it has them built in by default. here is the best jquery i could come up with by the way, im not sure how this could be refactored better (although i definitely know it could be). I had to do it like this because i have an 'x' inside the <p> flash

if($('.alert-success').clone().children().remove().end().text() != "") {
    $('.alert-success').fadeIn();
  }
  if($('.alert-error').clone().children().remove().end().text() != "") {
    $('.alert-error').fadeIn();
  }

EDIT: My layout contains:

<p class="alert alert-success"><a class="close" data-dismiss="alert">&times;</a><%= notice %></p>
<p class="alert alert-error"><a class="close" data-dismiss="alert">&times;</a><%= alert %></p>
Gareth
  • 133,157
  • 36
  • 148
  • 157
Tallboy
  • 12,847
  • 13
  • 82
  • 173

1 Answers1

1

No special methods here, I'd simply control how those tags are output with a surrounding if:

<% if notice %><p class="alert alert-success"><a class="close" data-dismiss="alert">&times;</a><%= notice %></p><% end %>
<% if alert %><p class="alert alert-error"><a class="close" data-dismiss="alert">&times;</a><%= alert %></p><% end %>
Gareth
  • 133,157
  • 36
  • 148
  • 157