def set_current_tenant( tenant_id = nil )

      if user_signed_in?

        @_my_tenants ||= current_user.tenants  # gets all possible tenants for user

        tenant_id ||= session[:tenant_id]   # use session tenant_id ?

        if tenant_id.nil?  # no arg; find automatically based on user
          tenant_id = @_my_tenants.first.id  # just pick the first one
        else   # validate the specified tenant_id before setup
          raise InvalidTenantAccess unless @_my_tenants.any?{|tu| tu.id == tenant_id}
        end

      else   # user not signed in yet...
        tenant_id = nil   # an impossible tenant_id
      end

      __milia_change_tenant!( tenant_id )
      trace_tenanting( "set_current_tenant" )

      true    # before filter ok to proceed
    end
def set_current_tenant( tenant_id = nil )

      if user_signed_in?

        @_my_tenants ||= current_user.tenants  # gets all possible tenants for user

        tenant_id ||= session[:tenant_id]   # use session tenant_id ?

        if tenant_id.nil?  # no arg; find automatically based on user
          tenant_id = @_my_tenants.first.id  # just pick the first one
        else   # validate the specified tenant_id before setup
          raise InvalidTenantAccess unless @_my_tenants.any?{|tu| tu.id == tenant_id}
        end

      else   # user not signed in yet...
        tenant_id = nil   # an impossible tenant_id
      end

      __milia_change_tenant!( tenant_id )
      trace_tenanting( "set_current_tenant" )

      true    # before filter ok to proceed
    end
------------------------------------------------------------------------------
 set_current_tenant -- sets the tenant id for the current invocation (thread)
 args
   tenant_id -- integer id of the tenant; nil if get from current user
 EXCEPTIONS -- InvalidTenantAccess
 ------------------------------------------------------------------------------