Skip to content

Commit

Permalink
add getter and setter but still maintain compatibility with using @ac…
Browse files Browse the repository at this point in the history
…count
  • Loading branch information
joshgoebel committed Jan 6, 2012
1 parent 9f48658 commit a5f8508
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 11 additions & 2 deletions README
Expand Up @@ -7,6 +7,9 @@ match this style and to get the current account key from the subdomain.

The methods are: account_url, account_host, and account_domain.

current_account can be used to get and set the currently active account.


Example:

class ApplicationController < ActionController::Base
Expand All @@ -15,9 +18,15 @@ Example:

protected
def find_account
@account = Account.find_by_username(account_subdomain)
self.current_account = Account.find_by_username(account_subdomain)
end
end

class UsersController < ApplicationController
def index
@users = current_account.users.all
end
end

class AccountController < ApplicationController
def new
Expand All @@ -40,7 +49,7 @@ Example:

Your domain: <%= account_url %>

By default, all the methods will query for @account.username as the account key, but you can
By default, all the methods will query for current_account.username as the account key, but you can
specialize that by overwriting default_account_subdomain. You can of course also pass it in
as the first argument to all the methods.

Expand Down
15 changes: 13 additions & 2 deletions lib/account_location.rb
@@ -1,11 +1,22 @@
module AccountLocation
def self.included(controller)
controller.helper_method(:account_domain, :account_subdomain, :account_host, :account_url)
controller.helper_method(:account_domain, :account_subdomain, :account_host, :account_url,
:current_account)
end

protected

def current_account
@current_account
end

def current_account=(account)
@current_account = account
end

def default_account_subdomain
@account.username if @account && @account.respond_to?(:username)
account = current_account || @account
account.username if account && account.respond_to?(:username)
end

def account_url(account_subdomain = default_account_subdomain, use_ssl = request.ssl?)
Expand Down

0 comments on commit a5f8508

Please sign in to comment.