I have 2 models Person and Address with a has and belongs to many join table association.
Using will_paginate and ransack.
When filtering on Date field, the first page is filtered correctly. When I click on any of the other paginations link, query changes from date(persons.dob) >= '2013-09-01')
to date(persons.dob) >= 2013)
class Person
has_many :person_addresses
has_many :addresses, through: :person_addresses
end
class Address
has_many :person_addresses
has_many :persons, through: :person_addresses
end
class PersonAddress
belongs_to :person
belongs_to :address
end
Persons' search form has dob_gteq
, dob_lteq
, name_cont
and addresses.street_cont
filters.
If I filter on dob_gteq
only, the first page works correctly. All other paginations causes:
ActionView::Template::Error (PG::UndefinedFunction: ERROR: operator does not exist: date >= integer
LINE 1: ...name" WHERE ((date(persons.dob) >= 2013 AN...
Removing the addresses.street_cont
filter from the search form allows it to work correctly and paginate as expected.
EDIT as requested controller action
@q = Person.search(params[:q]) @persons = @q.result(:distinct => true).paginate(:page => params[:page], :per_page => 30)
EDIT 2
Params coming in to search:
Parameters: {"utf8"=>"✓", "q"=>{"name_cont"=>"", "addresses_street_cont"=>"", "addresses_zipcode_cont"=>"", "dob_gteq"=>"09-01-2013", "dob_lteq"=>""}, "commit"=>"Filter"}
In my case, changing the column from a datetime to a date, which fits better, solved my problem.