aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/concerns/referential_support.rb
blob: f606e0e6341f11209f0137f006784c1d6f75e1e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module ReferentialSupport
  extend ActiveSupport::Concern

  included do
    before_action :switch_referential
    alias_method :current_referential, :referential
    helper_method :current_referential
  end

  def switch_referential
    authorize referential, :browse?
    Apartment::Tenant.switch!(referential.slug)
  end

  def referential
    @referential ||= find_referential
  end

  def find_referential
    current_organisation.find_referential params[:referential_id]
  end

end