Skip to content

Instantly share code, notes, and snippets.

@cherring
Created February 10, 2010 22:40
Show Gist options
  • Save cherring/300923 to your computer and use it in GitHub Desktop.
Save cherring/300923 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery
filter_parameter_logging :password
private
def set_current_account
@current_account = Account.find_by_subdomain!(request.subdomains.first)
end
end
class DashboardController < ApplicationController
before_filter :set_current_account
def index
end
end
# Edit this Gemfile to bundle your application's dependencies.
## Bundle edge rails:
gem "rails", :git => "git://github.com/rails/rails.git"
## Bundle the gems you use:
# gem "bj"
# gem "hpricot", "0.6"
# gem "sqlite3-ruby", :require_as => "sqlite3"
# gem "aws-s3", :require_as => "aws/s3"
## Bundle gems used only in certain environments:
# gem "rspec", :only => :test
# only :test do
# gem "webrat"
# end
RoutingTest::Application.routes.draw do |map|
# IMPORTANT: this setup assumes you route all *.myapp.com to localhost:3000 or
# something similar. This can be done by defining vhost in Apache or creating a PAC
# file for your local browser.
# This constraint captures all requests to hosts starting with www
# You could probably make this match the empty subdomain (myapp.local) but that
# means tightly coupling your hostname to your Rails routing configuration like this
#
# constraints(:host => "(^www\.myapp\.com)|(^myapp\.com)")
#
# which is IMO a very bad idea
#
constraints(:host => "^www\.") do
root :to => 'welcome#index'
resources :accounts # since accounts are not supposed to be scoped
end
# This is the default route when another subdomain is supplied
root :to => 'dashboard#index'
end
ActiveRecord::Schema.define(:version => 20100112224218) do
create_table "accounts", :force => true do |t|
t.string "subdomain"
t.datetime "created_at"
t.datetime "updated_at"
end
end
class WelcomeController < ApplicationController
def index
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment