Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rainhead/900818 to your computer and use it in GitHub Desktop.
Save rainhead/900818 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def current_user
@current_user ||= User.find_by_id(session[:user_id]) if signed_in?
end
def signed_in?
!! session[:user_id]
end
helper_method :current_user, :signed_in?
def current_user=(user)
@current_user = user
session[:user_id] = user.id
end
def logout!
@current_user = nil
session.delete :user_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment