lib/manage/fields/searcher.rb in manage-1.3.4 vs lib/manage/fields/searcher.rb in manage-1.3.5

- old
+ new

@@ -19,23 +19,26 @@ search_class.scope { resource_class.all } Object.const_set("#{resource_class.name + 'Searcher'}", search_class) search_fields.select {|f| not f.to_s.include?('.')}.each do |field| field_type = resource_class.columns_hash[field.to_s].type - if field_type == :text or field_type == :string + case field_type + when *[:text, :string] search_class.option field.to_sym do |scope, value| - scope.where "lower(#{field.to_s}) LIKE lower(?)", escape_search_term(value) + value.blank? ? scope : scope.where("lower(#{field.to_s}) LIKE lower(?)", escape_search_term(value)) end - elsif field_type == :datetime + when :datetime search_class.option field.to_sym do |scope, value| date = parse_date value scope.where("DATE(#{field.to_s}) >= ?", date) if date.present? end - elsif field_type == :integer + when :integer search_class.option field.to_sym + when :boolean + search_class.option field.to_sym else search_class.option field.to_sym do |scope, value| - scope.where "lower(#{field.to_s}) LIKE lower(?)", escape_search_term(value) + scope.where "#{field.to_s} = '?'", escape_search_term(value) end end end search_class