From 368945bede2de38f034b196c675b5cab093cf01b Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 3 Sep 2016 08:10:55 +0900 Subject: [PATCH] use `ActiveSupport.on_load` to hook into Active Record For avoiding autoloading these constants too soon. This affect the initialization of Active Record. Ref: https://github.com/rails/rails/issues/23589#issuecomment-229247727 --- lib/ransack.rb | 7 ------- lib/ransack/adapters/active_record.rb | 12 +++++++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/ransack.rb b/lib/ransack.rb index 180f76a..bbcd4e9 100644 --- a/lib/ransack.rb +++ b/lib/ransack.rb @@ -7,13 +7,6 @@ Ransack::Adapters.object_mapper.require_constants module Ransack extend Configuration class UntraversableAssociationError < StandardError; end; - - SUPPORTS_ATTRIBUTE_ALIAS = - begin - ActiveRecord::Base.respond_to?(:attribute_aliases) - rescue NameError - false - end end Ransack.configure do |config| diff --git a/lib/ransack/adapters/active_record.rb b/lib/ransack/adapters/active_record.rb index 0ffbf30..03efdac 100644 --- a/lib/ransack/adapters/active_record.rb +++ b/lib/ransack/adapters/active_record.rb @@ -1,5 +1,15 @@ require 'ransack/adapters/active_record/base' -ActiveRecord::Base.extend Ransack::Adapters::ActiveRecord::Base + +ActiveSupport.on_load(:active_record) do + extend Ransack::Adapters::ActiveRecord::Base + + Ransack::SUPPORTS_ATTRIBUTE_ALIAS = + begin + ActiveRecord::Base.respond_to?(:attribute_aliases) + rescue NameError + false + end +end require 'ransack/adapters/active_record/context'