Set tenant by subdomain

In application_controller.rb

  private
    def set_current_tenant

      if session[:tenant_id]
        @current_tenant = session[:tenant_id]

      else
        matching_tenants =
Tenant.find_by_subdomain!(request.server_name.split('.')[0])

        # raise InvalidTenantAccess if matching_tenants.blank?
        raise ActionController::RoutingError.new('Not Found') if
matching_tenants.blank?

        @current_tenant = matching_tenants.first.id
      end
      super(@current_tenant)
    end