Cannot get simple search by date to work with will_paginate


<% 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 %>


def, page)
paginate :per_page => 10, :page => page,
:conditions => [‘date like ?’, “%#{search}%”],
:order => ‘date desc’


def index
@page_title = ‘Attendances’
@attendances =[:search],

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)?


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

@attendances = @school.attendances.paginate :per_page => 10, :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?[(2i)]=8&search[(3i

Thanks for the help.

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
=, <, >, <=, >=.


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

Got it to work! Thanks for your help.

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 [email protected]

Thanks in advance

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs