From eab7216058517978134aff3401642eb56b3f7eef Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Thu, 23 Feb 2017 12:18:44 -0500 Subject: [PATCH] Add auto switch to default db for admin user --- Pearlception/app/models/user.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Pearlception/app/models/user.rb b/Pearlception/app/models/user.rb index 486d2eb..1c27f7e 100644 --- a/Pearlception/app/models/user.rb +++ b/Pearlception/app/models/user.rb @@ -5,10 +5,12 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - + def after_database_authentication if !self.admin Apartment::Tenant.switch!(Company.find(self.company_id).company_name.gsub(/'/,'').gsub(/\s/,'')) + else + Apartment::Tenant.switch! end end end