设计宝石闪光消息 [英] devise gem flash messages
问题描述
如果我使用带有 rails 的设计 gem,我如何让 flash 消息仅在其中包含内容时显示.
if i am using the devise gem with rails, how do i make the flash messages appear only when theres content inside of it.
rails 是否有一种简单的方法可以做到这一点,还是我需要在 jquery 中手动完成?
does rails have an easy way to do this or do i manually need to do it in jquery?
目前我使用 twitter bootstrap v2,默认情况下内置了它们.顺便说一下,这是我能想到的最好的 jquery,我不确定如何更好地重构它(尽管我肯定知道它可能是).我不得不这样做,因为我在 <p>
flash
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();
}
我的布局包含:
<p class="alert alert-success"><a class="close" data-dismiss="alert">×</a><%= notice %></p>
<p class="alert alert-error"><a class="close" data-dismiss="alert">×</a><%= alert %></p>
推荐答案
这里没有特殊的方法,我只是用周围的 if
来控制这些标签的输出方式:
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">×</a><%= notice %></p><% end %>
<% if alert %><p class="alert alert-error"><a class="close" data-dismiss="alert">×</a><%= alert %></p><% end %>
这篇关于设计宝石闪光消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!