Using searchlogic in Rails to find records by created_at year
I'm working on a Rails app wherein I want to be able to search for records created in a given year using the Searchlogic gem, but I can't figure out how to have Searchlogic only search by year. I tried this in my search form:
<%= f.date_select(:created_at_equals, :start_year => 2010, :end_year => 2015, :discard_day => true, :discard_month => true, :include_blank => true ) %>
but this returns a "not valid parameters" error with these parameters:
{"searc开发者_StackOverflow中文版h"=>{"collection_like"=>"", "spring"=>"0", "order"=>"descend_by_id", "user_email_like"=>"", "fall"=>"0", "created_at_equals(1i)"=>"2010", "created_at_equals(2i)"=>"", "created_at_equals(3i)"=>""}}
Any help would be greatly appreciated. Thanks in advance.
Eric
you can do one thing make two objects of datetime in which year should be for which you want to search and select the records of between these two objects.
Ex:- suppose you want to select records of year 2010. dateobj1 = "1/1/2010" dateobj2 ="31/12/2010"
And select the records >= dateobj1 and <= dateobj2.
精彩评论