簡體   English   中英

在控制器中使用current_tenant導致Rails充當租戶錯誤

[英]Rails Acts As Tenant error using current_tenant in controller

我正在使用Acts_as_tenant 該文檔說"adds a handy helper to your controllers current_tenant, containing the current tenant object"

但是,我想訪問模型中的當前租戶。 Tenant模型包含一列request_closed

我希望這能奏效:

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

我也嘗試過:

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

但是,我得到:

undefined local variable or method `current_tenant'

有沒有辦法訪問模型中的current_tenant?

謝謝您的幫助!

更新1

我認為這可以工作-在開發中可以,但是在我的Heroku登台服務器上卻不能。

應用控制器:

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

請求控制器:

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

????

這工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM