简体   繁体   English

在Rails中使用searchlogic按created_at年查找记录

[英]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. 我正在开发一个Rails应用程序,其中我希望能够使用Searchlogic gem搜索给定年份创建的记录,但是我不知道如何让Searchlogic仅按年份进行搜索。 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: 但这会使用以下参数返回“无效参数”错误:

{"search"=>{"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)"=>""}} {“ search” => {“ 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" 例如:-假设您要选择2010年的记录。dateobj1 =“ 1/1/2010” dateobj2 =“ 31/12/2010”

And select the records >= dateobj1 and <= dateobj2. 并选择记录> = dateobj1和<= dateobj2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM