Created
June 12, 2012 04:22
-
-
Save JamesChevalier/2914940 to your computer and use it in GitHub Desktop.
before_filter to determine which site to serve in a multi-site Rails app with a Pow dev environment
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] = case request.domain | |
when "domainA.dev" then "domainA" | |
when "domainB.dev" then "domainB" | |
else ENV['site'] || "domainA" | |
end | |
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