def set_current_tenant_by_subdomain(tenant = :account, column = :subdomain )
      self.class_eval do
        cattr_accessor :tenant_class, :tenant_column
      end

      self.tenant_class = tenant.to_s.camelcase.constantize
      self.tenant_column = column.to_sym

      self.class_eval do

        before_action :find_tenant_by_subdomain
        helper_method :current_tenant if respond_to?(:helper_method)


        private
          def find_tenant_by_subdomain
            if request.subdomains.last
              ActsAsTenant.current_tenant = tenant_class.where(tenant_column => request.subdomains.last.downcase).first
            end
          end

          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
def set_current_tenant_by_subdomain(tenant = :account, column = :subdomain )
      self.class_eval do
        cattr_accessor :tenant_class, :tenant_column
      end

      self.tenant_class = tenant.to_s.camelcase.constantize
      self.tenant_column = column.to_sym

      self.class_eval do

        before_action :find_tenant_by_subdomain
        helper_method :current_tenant if respond_to?(:helper_method)


        private
          def find_tenant_by_subdomain
            if request.subdomains.last
              ActsAsTenant.current_tenant = tenant_class.where(tenant_column => request.subdomains.last.downcase).first
            end
          end

          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
this method allows setting the current_tenant by reading the subdomain and looking
 it up in the tenant-model passed to the method. The method will look for the subdomain
 in a column referenced by the second argument.