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

发布于 2024-09-11 07:05:21 字数 639 浏览 2 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2024-09-18 07:05:21

您可以做一件事,创建两个日期时间对象,您要搜索其中的年份,并选择这两个对象之间的记录。

前任:-
假设您要选择 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文