Skip to content

Commit

Permalink
Use on_load hooks to enhance rails classes (#212)
Browse files Browse the repository at this point in the history
Fixes an issue where jbuilder on_load hooks are never run because acts_as_tenant loads the classes too early.
  • Loading branch information
jrafanie authored and ErwinM committed Dec 23, 2019
1 parent c419f81 commit fea563c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/acts_as_tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@

#$LOAD_PATH.shift

if defined?(ActiveRecord::Base)
ActiveRecord::Base.send(:include, ActsAsTenant::ModelExtensions)
ActiveSupport.on_load(:active_record) do |base|
base.include ActsAsTenant::ModelExtensions
end

if defined?(ActionController::Base)
ActionController::Base.extend ActsAsTenant::ControllerExtensions
end

if defined?(ActionController::API)
ActionController::API.extend ActsAsTenant::ControllerExtensions
ActiveSupport.on_load(:action_controller) do |base|
base.extend ActsAsTenant::ControllerExtensions
end

module ActsAsTenant
end

0 comments on commit fea563c

Please sign in to comment.