2017-04-21 1 views
0

Ruby on Rails를 기반으로하는 SaaS 앱을 만들고 있습니다.현재 세입자를 기록하는 방법은 무엇입니까?

거주자에는 하위 도메인이 있습니다.

방문은 사용자의 것이며, #current_user에서 가져옵니다. 또한 이번 방문을 현재 거주자와 연결하고 싶습니다. 내 경우는 다음과 같습니다

class Visit 
    belongs_to :user, optional: true 
    has_many :ahoy_events, class_name: 'Ahoy::Event' 

    belongs_to :site # the relationship with tenant 
end 

어떻게 현재의 세입자를 기록하는 일을 해킹 할 수 있습니까?

+1

https://github.com/ankane/ahoy#track-additional-values –

답변

0

그래서 :site은 실제로 입주자 모델입니까?

일부 ApplicationController 메서드를 만들어 세션에서 추적 할 수있는 현재 세입자를 저장하고 검색 할 수 있습니다.

class ApplicationController < ActionController::Base 

    def current_tenant=(tenant) 
    session[:tenant_id] = tenant.id 
    end 

    def current_tenant 
    Site.find(session[:tenant_id]) 
    end 

end