Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Some convenience methods making subdomains in Rails a whole lot easier.

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 rails-subdomain.gemspec

Rails Subdomain

Subdomains in rails are still a bit hairy.

This is a growing collection of helpers and monkey patches to make it better(tm).


My::Application.routes.draw do
  subdomain /\A(www|)\Z/, default: "www" do
    root to: "home#show"

  subdomain :admin, module: "admin", as: "admin" do
    root to: "admin/dashboard#show"

This will route and in the first subdomain scope, and in the second scope. If you have different number of TLDs (the .com bit, default is 1) change config.action_dispatch.tld_length in your config/application.rb or any config/environments/*.rb file. For example, would need to change the tld_length to 2 (

When on the home show page, admin_root_path will render a full URL,, because it knows you'll cross subdomains. From the admin dashboard, admin_root_path will be /, but root_path will be

There will be test helpers added for capybara/selenium/cucumber super-soon.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.