0
我有我想要做的條件驗證像這樣一類用戶之前運行的方法:一類負荷
if $organization.first_name_last_name
validates :name_first, presence: true,
length: { maximum: 50 },
:if => :local_authentication?
validates :name_last, presence: true,
length: { maximum: 50 },
:if => :local_authentication?
但是這個全球性組織變量是包含特定設置的子域的對象,並進行初始化在應用程序控制器的before_filter中。
class ApplicationController < ActionController::Base
before_filter :load_organization
...
def load_organization
$organization = Organization.find_by_subdomain(request.subdomain).settings
end
我的問題是如何使load_organization在User類加載之前運行,以便正確設置組織變量。
感謝您的回答!這解決了它。 我使用的公寓寶石(https://github.com/influitive/apartment),其允許通過不同的數據庫依賴於子域來處理每個請求。在第一次嘗試啓用多租戶時,我爲每個實例創建了一個獨立的組織對象來保存配置參數(取決於客戶端的需求)。這只是一個臨時解決方案 – rtemperv