简体   繁体   中英

want to customise the current_user methode of devise gem

I want to user current_user method for two purpose.

I have user gmail log in and personal registration from site.

But current_user method of devise gem is not working for gmail user.

for gmail user I used below method

 helper_method :current_user

 def current_user
   @current_user ||= User.find(session[:user_id]) if session[:user_id]
 end

kindly help me to fix this. Thanks

I got solution by my self letter on.

Below code is the solution of above problem

alias_method :devise_current_user, :current_user
  def current_user
    if session[:user_id].blank?
      devise_current_user
    else
      User.find(session[:user_id])
    end   
  end

This works fine for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM