I would like to set the number of seconds a flash notice is shown to the user, before it is automatically dismissed.
A flash message is a way to communicate information with the users of your Rails application so they can know what happens as a result of their actions. Example messages: “Password changed correctly” (confirmation) “User not found” (error)
Flash messages are notifications and alerts that pop up in the interface of an application in order to communicate with the user and ease of interaction. Applications often apply flash messages to tell the user if the login was correct or to confirm the success of the action triggered by clicking a button.
You can use some simple JavaScript on your page (using jQuery in this example):
$('document').ready(function() {
setTimeout(function() {
$('#flash').slideUp();
}, 3000);
});
Assuming the id of the HTML element holding your flash message is #flash
, this will slide it up and hide it after 3000 milliseconds (3 seconds).
Just combining what @LouisSimoneau and @rlecaro2 already mentioned – I currently use:
function clearNotice(){
$(".notice").animate({opacity:'0'}, 1500);
}
Note that if your using rails 4 with turbolinks, you'll need to call it from a ready
function:
$(document).ready(ready);
$(document).on('page:load', ready);
var ready = function() {
setTimeout(clearNotice, 1000); //Flash fade
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With