# Cannot get simple search by date to work with will\_paginate

**URL:** <https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584>\
**Category:** Rails\
**Created:** [August 8, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584 "2007-08-08T20:38:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [August 8, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584/1 "2007-08-08T20:38:00Z")

</div>

View:

\<% form\_tag attendances\_path, :method =\> ‘get’ do %\>

Search attendances by date: \<%= date\_select :search, params[:search], :use\_short\_month =\> true, :order =\> [:month, :day, :year] %\> \<%= submit\_tag 'Search', :name =\> nil %\>

\<% end %\>

Model:

def self.search(search, page)  
paginate :per\_page =\> 10, :page =\> page,  
:conditions =\> [‘date like ?’, “%#{search}%”],  
:order =\> ‘date desc’  
end

Controller:

def index  
@page\_title = ‘Attendances’  
@attendances = @school.attendances.search(params[:search],  
params[:page])  
end

Why is this not working? Thanks for any help!

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [August 8, 2007, 11:38pm UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584/2 "2007-08-08T23:38:29Z")

</div>

What isn’t working? What’s the error? What is the expected behaviour?  
How does the actual behaviour differ from the expected?

Is it necessary for you to define a search method in your model,  
rather than just call @school.paginate(:all, :conditions =\> blah)?

Adam

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [August 9, 2007, 1:18am UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584/3 "2007-08-09T01:18:38Z")

</div>

I guess I don’t need it a search method so I added this to my  
controller:

@attendances = @school.attendances.paginate :per\_page =\> 10, :page =\>  
params[:page],  
:conditions =\> [‘date  
like ?’, “%#{params[:search]}%”],  
:order =\> ‘date desc’

My intended behavior is to simply search attendances by an exact date.  
I don’t get an error but no records show up even if I search the  
correct date. Also, is there a way to have a cleaner url when  
searching that this?

[domain.com/attendances?search[(2i)]=8&search[(3i](http://domain.com/attendances?search%5B%282i%29%5D=8&search%5B%283i)  
%29%5D=8&search%5B%281i%29%5D=2007

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [August 9, 2007, 4:32am UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584/4 "2007-08-09T04:32:54Z")

</div>

blinksale’s invoice filter looks like it’s using a bunch of custom  
routes and then parsing the parameters. Read up on rails routes to  
figure out how to implement these types of urls.

And your conditions look wrong. If you’re searching by date, and the  
date column in your database is a date type, then you shouldn’t be  
using ‘like’. You should be using date comparison operators, such as  
=, \<, \>, \<=, \>=.

Adam

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [August 9, 2007, 2:55am UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584/5 "2007-08-09T02:55:44Z")

</div>

I really like blinksale’s invoice filter functionality. Is there a  
plugin for something like that?

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [August 9, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584/6 "2007-08-09T22:22:56Z")

</div>

Got it to work! Thanks for your help.

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [December 5, 2007, 5:37am UTC](https://www.ruby-forum.com/t/cannot-get-simple-search-by-date-to-work-with-will-paginate/111584/7 "2007-12-05T05:37:07Z")

</div>

jko170 wrote:

> Got it to work! Thanks for your help.

Hi I do face same type of issue in my project can u share how u over  
come that…  
My mail id is removed\_email\_address@domain.invalid

Thanks in advance
