开发者

customizing devise to update user attribute on signin and signout

I have a customer devise controller and i wan to set my sign up action to update a user status to online when the user signs in and off line when the users logout. I have

def signin
super
end

I want to update the users status attribute to online on login and offline on开发者_如何学运维 logout. Pls any help here


You may be missing attr_accesible declaration for the "status" attribute of User table?


You can use the after_sign_in_path_for and after_sign_out_path_for hooks provided in devise. Just override those methods in your ApplicationController. Eg.

class ApplicationController < ActionController::Base
  private

  def after_sign_in_path_for(resource_or_scope)
    #update user status to online
    root_path
  end

  def after_sign_out_path_for(resource_or_scope)
    #update user status to offline
    root_path
  end
end

More info here: devise wiki

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜