Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peremarshall/37f1e834759604e97bbd5a40b40ad4d8 to your computer and use it in GitHub Desktop.
Save peremarshall/37f1e834759604e97bbd5a40b40ad4d8 to your computer and use it in GitHub Desktop.
Subdomain routing in application controller
class ApplicationController < ActionController::Base
before_filter :init
def init
@current_user = current_user if current_user
domain_data = request.host.split(".")
ignored_subdomains = ["www"]
if domain_data.count == 3
context = domain_data[0]
end
if request.format.json?
@portal = @current_user.partner
elsif context && !ignored_subdomains.include?(context)
@portal = Partner.where("subdomain = ?", context).first
end
if @current_user && (@current_user.admin? || (@portal && @portal == @current_user.partner))
@portal_access = true
elsif @current_user && params[:controller] != "sessions" && !request.format.json?
@portal_access = false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment