Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
Created June 12, 2012 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesChevalier/2914870 to your computer and use it in GitHub Desktop.
Save JamesChevalier/2914870 to your computer and use it in GitHub Desktop.
before_filter to determine which site to serve in a multi-site Rails app
def set_site
if RAILS_ENV == "development"
session[:site] = ENV['site'] || "domainA" # Default to domainA in development
else session[:site].blank?
if RAILS_ENV == "staging"
session[:site] = case request.subdomains.last # *.yourstagingdomain.com
when "domainA" then "domainA"
when "domainB" then "domainB"
end
elsif RAILS_ENV == "production"
session[:site] = case request.domain
when "domainA.com" then "domainA"
when "domainB.com" then "domainB"
else "domainA"
end
else
session[:site] = "domainA" # default
end
end
if @site.nil?
@site ||= Site.find_by_name(session[:site])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment