lib/ransack/configuration.rb in ransack-3.2.1 vs lib/ransack/configuration.rb in ransack-4.0.0

- old
+ new

@@ -25,19 +25,19 @@ end self.predicates = PredicateCollection.new self.options = { - :search_key => :q, - :ignore_unknown_conditions => true, - :hide_sort_order_indicators => false, - :up_arrow => '▼'.freeze, - :down_arrow => '▲'.freeze, - :default_arrow => nil, - :sanitize_scope_args => true, - :postgres_fields_sort_option => nil, - :strip_whitespace => true + search_key: :q, + ignore_unknown_conditions: true, + hide_sort_order_indicators: false, + up_arrow: '▼'.freeze, + down_arrow: '▲'.freeze, + default_arrow: nil, + sanitize_scope_args: true, + postgres_fields_sort_option: nil, + strip_whitespace: true } def configure yield self end @@ -53,15 +53,15 @@ Constants::SUFFIXES.each do |suffix| compound_name = name + suffix self.predicates[compound_name] = Predicate.new( opts.merge( - :name => compound_name, - :arel_predicate => arel_predicate_with_suffix( + name: compound_name, + arel_predicate: arel_predicate_with_suffix( opts[:arel_predicate], suffix ), - :compound => true + compound: true ) ) end if compounds end @@ -97,9 +97,22 @@ # config.ignore_unknown_conditions = false # end # def ignore_unknown_conditions=(boolean) self.options[:ignore_unknown_conditions] = boolean + end + + # By default Ransack ignores empty predicates. Ransack can also fallback to + # a default predicate by setting it in an initializer file + # like `config/initializers/ransack.rb` as follows: + # + # Ransack.configure do |config| + # # Use the 'eq' predicate if an unknown predicate is passed + # config.default_predicate = 'eq' + # end + # + def default_predicate=(name) + self.options[:default_predicate] = name end # By default, Ransack displays sort order indicator arrows with HTML codes: # # up_arrow: '▼'