Skip to content

Instantly share code, notes, and snippets.

@george
Created August 13, 2008 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save george/5239 to your computer and use it in GitHub Desktop.
Save george/5239 to your computer and use it in GitHub Desktop.
# note: this code could be tightened up a lot,
# but the concept should be fairly clear
class HomePageController < ApplicationController
# this ensures 'current_user' is populated with the logged in user
before_filter :login_required
def index
@user = current_user
@lists = @user.lists
@other_things_the_user_owns = @user.other_things_the_user_owns
end
# terrible name
def alternate_user_home
fetch_user_or_redirect
@lists = @user.lists
@other_things_the_user_owns = @user.other_things_the_user_owns
render :action => 'index'
end
# 'private' methods are not routable so no one can access them through a URL
private
def fetch_user_or_redirect
@user = User.find_by_login(params[:login])
# send them on their way if params[:login] was nil or
# we couldn't find a matching user or they shouldn't
# have access to this user's home page
#
# allowed_to_view_home_page_for(@user) needs to be implemented
unless @user && current_user.allowed_to_view_home_page_for(@user)
flash[:error] = 'Fail!'
redirect_to(whatever_path)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment