https://github.com/shuber/subdomain_account
A rails plugin that handles subdomain accounts
https://github.com/shuber/subdomain_account
Last synced: about 1 year ago
JSON representation
A rails plugin that handles subdomain accounts
- Host: GitHub
- URL: https://github.com/shuber/subdomain_account
- Owner: shuber
- License: mit
- Created: 2008-06-04T22:30:31.000Z (almost 18 years ago)
- Default Branch: master
- Last Pushed: 2009-01-09T20:04:09.000Z (over 17 years ago)
- Last Synced: 2024-04-24T15:23:50.563Z (about 2 years ago)
- Language: Ruby
- Homepage:
- Size: 104 KB
- Stars: 58
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- Changelog: CHANGELOG
- License: MIT-LICENSE
Awesome Lists containing this project
README
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](mailto:shuber@huberry.com)