2017-06-06 8 views
0

Rails 4アプリケーションで個々のフラッシュ[:エラー]メッセージの表示時間を長くする最も簡単な方法は何ですか?Railsがフラッシュ[:エラー]メッセージの継続時間を長くする

メッセージがコントローラにあり、適切なセクションでは、このようになりますんコード:

else 
    flash[:notice] = t(:no_new_media, source: @channel.external_source.capitalize) 
    flash[:error] = @error['message'] if @error.present? 
    redirect_to admin_channel_path(@channel) 
    end 

私は、エラーメッセージの表示時間を長くしたいのですが、私はどちらかの方法を気にしません予告について

+0

https://stackoverflow.com/questions/21467157/how-do-i-dismiss-a-rails-flash-message-after-some-duration – Pavan

答えて

0

新しいカスタムフラッシュメッセージタイプを作成する必要があります。詳細はhereです。

# app/controllers/application_controller.rb 
class ApplicationController 
    ... 
    add_flash_types :error, :another_custom_type 
end 

# app/controllers/users_controller.rb 
class UsersController < ApplicationController 
    def create 
    ... 
    redirect_to home_path, 
     another_custom_type: "An error message for the user" 
    end 
end 

今、あなたのビューにチェックflash[:another_custom_type].present?とそのに基づいてメッセージの設定した時間。

0

私はわかりませんが、あなたがこのように試すことができます:私はフラッシュメッセージを持っているHTML要素のidが#testで考える reference

$('document').ready(function() { 
    setTimeout(function() { 
    $('#test').slideUp(); 
    }, 5000); 
}); 

、これは5(5000ミリ秒後にそれを隠します秒)。

OR

app/assets/javascripts/application.js.coffee 

$ -> 
    flashCallback = -> 
    $(".flash-message").fadeOut() 
    $(".flash-message").bind 'click', (ev) => 
    $(".flash-message").fadeOut() 
    setTimeout flashCallback, 3000 

これはあなたを助けることを願っています。

+0

@Craigあなたが私の答えに満足すれば、それを正してください。投票する –

関連する問題