Permalink
Browse files

Fixed sql search for will_paginate 3.0 and activerecord 3.1

  • Loading branch information...
1 parent d7daf23 commit db82906edaeb03885e6ae4064ef18a855f94c719 @JangoSteve JangoSteve committed Nov 12, 2011
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/search_engine/sql.rb
View
@@ -22,14 +22,16 @@ def self.add_sql_search_to(model, *fields)
order = opts[:order] || "LOWER(#{self.table_name}.name) ASC"
pagination_options = {}
- pagination_options[:page] = opts.delete(:page) if opts[:page].present?
+ pagination_options[:page] = opts[:page].present? ? opts.delete(:page) : 1
pagination_options[:per_page] = opts.delete(:per_page) if opts[:per_page].present?
conditions_text = fields.map{|field| "LOWER(#{self.table_name}.#{field}) LIKE :like_query"}.join(" OR ")
conditions = [conditions_text, {:like_query => "%#{query.downcase}%"}]
- results = self.all(:conditions => conditions, :order => order, :limit => limit)
+ results = self
results = results.paginate(pagination_options) unless pagination_options.empty?
+ results = results.limit(limit) if limit.present?
+ results = results.all(:conditions => conditions, :order => order)
return results
end

0 comments on commit db82906

Please sign in to comment.