Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Attributes After Sign In Devise

I am using devise in a Rails 3 app.

I would like to update some attributes of a User on a successful sign in.

I am doing it the following way:

I added following code to application_controller.rb

def after_sign_in_path_for(user)
   @user = current_user
   @user.status = "online"
   @user.save

   root_path
end

Is it possible to have a different method for doing this and not using the method that is used for defining the after_sign_in_path ?

Thanks in advance!

like image 261
Nirav Shah Avatar asked Jul 01 '11 11:07

Nirav Shah


1 Answers

You can do this with hooks to warden.

##config/initializers/devise.rb

Warden::Manager.after_authentication do |user,auth,opts|
  user.update_attribute(:currently_signed_in, true)
end

Warden::Manager.before_logout do |user,auth,opts|
  user.update_attribute(:currently_signed_in, false)
end
like image 127
Kosmonaut Avatar answered Oct 16 '22 04:10

Kosmonaut