Every repository with this icon (
Every repository with this icon (
tree cd2cf493269c6c685e94c2cb9361a439c250d8cb
parent ac9adb5723a6e8e890d9614a95c9a9abcd420462
| name | age | message | |
|---|---|---|---|
| |
CHANGELOG | ||
| |
MIT-LICENSE | Thu Jun 05 11:49:34 -0700 2008 | |
| |
README.markdown | Fri Jan 09 11:01:38 -0800 2009 | |
| |
Rakefile | Thu Jun 05 11:49:34 -0700 2008 | |
| |
init.rb | Fri Jan 09 10:55:21 -0800 2009 | |
| |
lib/ | ||
| |
subdomain_account.gemspec | ||
| |
test/ |
subdomain_account
A rails gem/plugin that handles subdomain accounts
Installation
gem install shuber-subdomain_account --source http://gems.github.com
OR
script/plugin install git://github.com/shuber/subdomain_account.git
Usage
Simply add before_filter :subdomain_account_required for any actions that require a subdomain. A :model will then be searched
by :field for the current subdomain. The result of that query is stored in a controller instance method called current_account.
In the example below, the current_account would be set to the result of Account.find_by_subdomain(request.subdomains.first).
The :model and :field options are customizable, see below.
class ProjectsController < ApplicationController
before_filter :subdomain_account_required
def index
render :text => current_account.subdomain
end
end
By default the :model to use for looking up records is Account and the :field to search by is :subdomain. You can change
this by modifying the controller's subdomain_account_options attribute like so:
class ApplicationController < ActionController::Base
self.subdomain_account_options.merge!(:model => Company, :field => :username)
end
When a subdomain is required but the current_account was not found, the controller calls the subdomain_account_not_found instance
method which simply renders a 404. You can overwrite this method to change this behavior.
Contact
Problems, comments, and suggestions all welcome: shuber@huberry.com








