Skip to content

Instantly share code, notes, and snippets.

@nanosplit
Last active May 22, 2018 02:54
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 nanosplit/02b5e9ddc43906a35fbb830057e6ed82 to your computer and use it in GitHub Desktop.
Save nanosplit/02b5e9ddc43906a35fbb830057e6ed82 to your computer and use it in GitHub Desktop.
#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