如何让我的错误消息淡出?在RubyOnRails 3中

时间:2011-07-14 15:05:17

标签: jquery ruby-on-rails-3 fadeout

我想要显示的错误

flash[:error] = "Invalid username/password combination."

我试过

$(document).ready( function() {// When the Dom is ready
    $('.error').hide();//Hide the div
    $('.alert').hide();
    $('.notice').hide();
    $('.success').hide();
    $('.info').hide();

    $(".error").fadeOut(2000); //Add a fade out effect that will last for 2000 millisecond
    $(".alert").fadeOut(2000);
    $(".notice").fadeOut(2000);
    $(".success").fadeOut(2000);
    $(".info").fadeOut(2000);

});

没有成功..我已经包含了javascript文件

<%= javascript_include_tag 'jquery-1.3.2' %>

1 个答案:

答案 0 :(得分:6)

您无法获取错误消息。

flash[:error] = "Invalid username/password combination."

只输出原始文本。

 flash[:error] = "<div class='error'>Invalid username/password
 combination.</div>"

将其包装在容器中。

然后您可以使用jQuery淡出容器。

$(".error").fadeOut(2000);