Skip to content

Instantly share code, notes, and snippets.

@lscott3
Created May 17, 2012 02:06
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 lscott3/2715650 to your computer and use it in GitHub Desktop.
Save lscott3/2715650 to your computer and use it in GitHub Desktop.
Authlogic application controller
class ApplicationController < ActionController::Base
helper_method :current_account, :current_user # you may have others that go here too
private
# I added this so that way I can just use current_account just like current_user
def current_account
@current_account = Account.find_by_subdomain(request.subdomain)
return @current_account
end
def current_user_session
return @current_user_session if defined?(@current_user_session)
# This line here is the main thing that you need to add.
# Notice the current_account.user_sessions.find
@current_user_session = current_account.user_sessions.find unless current_account.nil?
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment