What you do not need, you need to set a persistent cookie when creating a session, and then get this value when setting the current user.
In ApplicationController just change the current_user method to:
def current_user return unless cookies.signed[:permanent_user_id] || session[:user_id] begin @current_user ||= User.find(cookies.signed[:permanent_user_id] || session[:user_id]) rescue Mongoid::Errors::DocumentNotFound nil end end
And in your SessionsController change your create to set a cookie if the user wants:
def create auth = request.env["omniauth.auth"] user = User.where(:provider => auth['provider'], :uid => auth['uid']).first || User.create_with_omniauth(auth) session[:user_id] = user.id cookies.permanent.signed[:permanent_user_id] = user.id if user.really_wants_to_be_permanently_remembered redirect_to root_url, :notice => "Signed in!" end
David
source share