I want to make the flash message disappear after a few seconds. So I use these codes:
$(function() {
$('.alert').slideUp(1500);
});
.alert is the bootstrap class I add to the flash message.
And my app achieved user login/logout function only through omniauth. (with facebook and google plus) The login/logout codes listed in the end.
When I log in, the flash message disappeared like what I thought. But when I log out, the flash didn't disappear.
But if I use these codes, this function will work correctly. (but slightly different than what I want)
$(function() {
setInterval(function(){
$('.alert').slideUp(500);
}, 1000);
});
login/out codes:
class SessionsController < ApplicationController
def create
auth_data = request.env['omniauth.auth']
auth = Authorization.find_by( provider: auth_data['provider'], uid: auth_data['uid'] )
user = auth.nil? ? User.create_with_omniauth(auth_data) : auth.user
session[:user_id] = user.id
if !user.email
redirect_to edit_user_path(user), :alert => "Please enter your email address."
else
redirect_to root_url, :notice => "Signed in!"
end
end
def destroy
reset_session
redirect_to root_url, :notice => "Signed out!"
end
def new
end
def failure
redirect_to root_url, :alert => "Authentication error: #{params[:message].humanize}"
end
end
try this
$(function() {
setTimeout(function(){
$('.alert').slideUp(500);
}, 1000);
});
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