Last active
May 22, 2018 02:54
-
-
Save nanosplit/02b5e9ddc43906a35fbb830057e6ed82 to your computer and use it in GitHub Desktop.
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
#routes | |
constraints(AffiliateSubdomain) do | |
match '/', to: 'affiliates/properties#index', via: :all | |
end | |
#libs/affiliate_subdomain.rb | |
class AffiliateSubdomain | |
def self.matches? request | |
matching_site?(request) | |
end | |
def self.matching_site?(request) | |
self.get_affiliate(request).any? | |
end | |
def self.get_subdomain(request) | |
if request.subdomain.include?('www') | |
request.host[4..-1] # remove 'www.' | |
else | |
request.host | |
end | |
end | |
def self.get_affiliate(request) | |
req = self.get_subdomain(request) | |
Affiliate.where(:slug => req) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment