在Rails中使用searchlogic按created_at年份查找记录
我正在开发一个 Rails 应用程序,其中我希望能够使用 Searchlogic gem 搜索在给定年份创建的记录,但我不知道如何让 Searchlogic 仅按年份搜索。我在搜索表单中尝试了此操作:
<%= f.date_select(:created_at_equals, :start_year => 2010, :end_year => 2015, :discard_day => true, :discard_month => true, :include_blank => true ) %>
但这会返回以下参数的“无效参数”错误:
{"搜索"=>{"collection_like"=>"", “弹簧”=>“0”, “order”=>“descend_by_id”, “user_email_like”=>“”, “下降”=>“0”, "created_at_equals(1i)"=="2010", "created_at_equals(2i)"=="", “created_at_equals(3i)”=>“”}}
任何帮助将不胜感激。提前致谢。
埃里克
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:
{"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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做一件事,创建两个日期时间对象,您要搜索其中的年份,并选择这两个对象之间的记录。
前任:-
假设您要选择 2010 年的记录。
日期对象1 = "1/1/2010"
dateobj2 ="31/12/2010"
并选择记录 >= dateobj1 和 <= dateobj2。
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.