Skip to content
Browse files

subclasses extensions are picked up when first model inherits from ar…

…::base
  • Loading branch information...
1 parent 82a38e0 commit 1c43100edd2a91653c3f1c404a46c0cd6d0db146 @rindek committed Jul 18, 2012
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/kaminari/models/active_record_extension.rb
View
13 lib/kaminari/models/active_record_extension.rb
@@ -4,19 +4,22 @@ module Kaminari
module ActiveRecordExtension
extend ActiveSupport::Concern
included do
+ @_subclasses_loaded = false
# Future subclasses will pick up the model extension
class << self
def inherited_with_kaminari(kls) #:nodoc:
+ # First model should also force subclasses to pick up the model extension as well
+ unless @_subclasses_loaded
+ self.descendants.each do |kls|
+ kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ActiveRecord::Base
+ end
+ @_subclasses_loaded = true
+ end
inherited_without_kaminari kls
kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ActiveRecord::Base
end
alias_method_chain :inherited, :kaminari
end
-
- # Existing subclasses pick up the model extension as well
- self.descendants.each do |kls|
- kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ActiveRecord::Base
- end
end
end
end

0 comments on commit 1c43100

Please sign in to comment.
Something went wrong with that request. Please try again.