Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created March 30, 2012 17:33
Show Gist options
  • Save brandon-beacher/2253206 to your computer and use it in GitHub Desktop.
Save brandon-beacher/2253206 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :current_user
def current_user
@current_user ||= User.find_by_id(session[:user_id])
end
private
def require_user
unless current_user.present?
flash[:info] = "You'll need to sign in to do that!"
redirect_to new_sign_in_path
end
end
end
class UsersController < ApplicationController
before_filter :require_user
def show
@user = User.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment