Cannot get simple search by date to work with will_paginate

View:

<% form_tag attendances_path, :method => 'get' do %>   <p>Search attendances by date:     <%= date_select :search, params[:search], :use_short_month => true, :order => [:month, :day, :year] %>     <%= submit_tag 'Search', :name => nil %>   </p> <% 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!

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

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%5B%282i%29%5D=8&search%5B%283i %29%5D=8&search%5B%281i%29%5D=2007

Thanks for the help.

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

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

Got it to work! Thanks for your help.