def set_current_tenant_by_subdomain_or_domain(tenant = :account, primary_column = :subdomain, second_column = :domain )
      self.class_eval do
        cattr_accessor :tenant_class, :tenant_primary_column, :tenant_second_column
      end

      self.tenant_class = tenant.to_s.camelcase.constantize
      self.tenant_primary_column = primary_column.to_sym
      self.tenant_second_column = second_column.to_sym

      self.class_eval do

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


        private
          def find_tenant_by_subdomain_or_domain
            if request.subdomains.last
              ActsAsTenant.current_tenant = tenant_class.where(tenant_primary_column => request.subdomains.last.downcase).first
            else
              ActsAsTenant.current_tenant = tenant_class.where(tenant_second_column => request.domain.downcase).first
            end
          end

          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
def set_current_tenant_by_subdomain_or_domain(tenant = :account, primary_column = :subdomain, second_column = :domain )
      self.class_eval do
        cattr_accessor :tenant_class, :tenant_primary_column, :tenant_second_column
      end

      self.tenant_class = tenant.to_s.camelcase.constantize
      self.tenant_primary_column = primary_column.to_sym
      self.tenant_second_column = second_column.to_sym

      self.class_eval do

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


        private
          def find_tenant_by_subdomain_or_domain
            if request.subdomains.last
              ActsAsTenant.current_tenant = tenant_class.where(tenant_primary_column => request.subdomains.last.downcase).first
            else
              ActsAsTenant.current_tenant = tenant_class.where(tenant_second_column => request.domain.downcase).first
            end
          end

          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
01/27/2014 Christian Yerena / @preth00nker
 this method adds the possibility of use the domain as a possible second argument to find
 the current_tenant.