ruby-on-railsacts-as-tenant

Rails Acts As Tenant error using current_tenant in controller


I'm using Acts_as_tenant. The doc says "adds a handy helper to your controllers current_tenant, containing the current tenant object".

But, I'd like to access the current tenant in a model. The Tenant model contains a column - request_closed.

I wish this worked:

class Worequest < ActiveRecord::Base
  acts_as_tenant(:tenant)
  closedcode = current_tenant.request_closed
  scope :notclosed, where("statuscode_id < ?", closedcode )

I also tried:

closedcode = ActsAsTenant.current_tenant.request_closed
and
closedcode = self.tenant.request_closed

But, I get:

undefined local variable or method `current_tenant'

Is there a way to access the current_tenant in a model?

Thanks for the help!

UPDATE1

I thought this would work - it does in development but not on my Heroku staging server.

Application Controller:

class ApplicationController < ActionController::Base

  protect_from_forgery

  set_current_tenant_by_subdomain(:tenant, :subdomain)

  before_filter :set_tenant_codes
    def set_tenant_codes
      $requestclosed = current_tenant.request_closed
    end

Request Controller:

  scope :notclosed, where("statuscode_id < ?", $requestclosed )

????


Solution

  • This worked:

      def self.closed
        where("statuscode_id = ?", ActsAsTenant.current_tenant.request_closed)
      end