Created
June 12, 2012 04:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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