Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# routes.rb (checks if subdomains is present in the request object then sends it off to the correct location)
Rails.application.routes.draw do
constraints MicrositeConstraint do
root to: 'microsites#index', as: 'microsite_root'
end
end
class MicrositeConstraint
def self.matches?(request)
taken = %w(
api
assets
images
www
)
request.subdomain.present? && !request.subdomain.in?(taken)
end
end
# application_controller.rb (used in application to load the correct model based on the subdomain)
def current_microsite
return unless request.subdomain.present? && request.subdomain != 'www'
@microsite ||= Microsite.active.find_by!(host: request.subdomain)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.