0.0
No commit activity in last 3 years
No release in over 3 years
subdomainitis provides easy, simple support for using wildcard subdomains as controller parameters in Rails 3
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 3.0.3
 Project Readme

Subdomainitis: transparently use subdomains as parameters in Rails 3

Installation and usage

To install, add gem "subdomainitis" to your Gemfile. Then modify your routes.rb file; see the example below for usage.

require 'subdomainitis'

MyProject::Application.routes.draw do
  extend Subdomainitis

  resources :spams

  main_domain do
    resource :foos
  end

  subdomain_as(:account) do
    resources :bars
  end

  use_fake_subdomains! unless Rails.env.production?
end

In the example above, the routes for spams will work regardless of the presence of a subdomain. However, the foos routes will only work if accessed WITHOUT using a subdomain; only http://mycompany.com/foos will work.

Accessing bars routes will only work when a subdomain is provided. Additionally, the specific subdomain is passed into the controller as a path parameter, as specified by the first argument to subdomain_as. For example, http://subdomain.mycompany.com/bars resolves to {:controller => 'bars', :action => 'index', :account => 'subdomain'}.

URL generation should work transparently as well; make sure you're using url instead of path generation (ie, foos_url instead of foos_path). Subdomainitis tries to fail fast by raising exceptions when a functional URL cannot be generated.

Call use_fake_subdomains! to use the _subdomain GET parameter instead of an actual subdomain. This is useful for development where wildcard subdomains aren't possible, or for testing environments like Cucumber that don't support subdomains. Enabling this mode should be completely transparent if you're using URL generators.

No changes to controllers are necessary.

Issues

Though this library seems to work fine for me, there are probably bugs and untested corner cases. Currently only named routes have been verified to work.

The implementation could probably be cleaner, and relies on internal Rails APIs that may be change in future versions.