我在試圖從設計中獲取current_user時遇到了實際問題,從此處確定帳戶ID,然後將此作爲變量從此gem傳遞給set_current_tenant_to方法:https://github.com/ErwinM/acts_as_tenant。在application_controller中設置類和方法變量
在我的應用程序控制器我有:
class ApplicationController < ActionController::Base
protect_from_forgery # See ActionController::RequestForgeryProtection for details
helper :all # include all helpers, all the time
def get_current_account_id
current_account_user = current_user
current_account_id = current_account_user.account_id
current_account_id
end
current_account = Account.find(get_current_account_id)
set_current_tenant_to(current_account)
我知道get_current_account_id推導出正確的ACCOUNT_ID,因爲當我把它放在一個電話的before_filter我可以在日誌中看到它輸出正確的數字。但是,當我運行此我得到以下錯誤:
Routing Error
undefined local variable or method `get_current_account_id' for ApplicationController:Class
任何意見或指示我如何能得到這個工作將不勝感激。
感謝您的嘗試,但它不工作。 有了這個在我的控制器: '高清self.get_current_account_id current_user.account_id 結束 current_account = Account.find(get_current_account_id) set_current_tenant_to(current_account)' 我現在得到了如下回應: '路由錯誤 ApplicationController:Class'的未定義局部變量或方法'current_user':類' – Betjamin 2012-03-22 14:51:55
混淆來自類和實例方法的衝突...乍一看,租戶文檔看起來很有趣,因爲它們看起來像是在課堂設置中運行,但那會鎖定t他認爲第一次運行,而不是運行它的每一個請求...我建議澄清與該作者的那個寶石... – DGM 2012-03-22 15:00:45