Rails 使用 MetaSearch 按日期过滤
我有一些在视图中显示的记录。它们有 start_date
和 end_date
。 当我访问视图时,默认情况下我希望它只显示日期未过期的记录。 过期被定义为:
- 结束日期和开始日期<=现在,并且
- 结束日期晚于开始日期
然后我想要一个复选框来显示所有记录,包括已过期的记录。
我该如何处理这个问题?
I have some records which I show in a view. They have start_date
and end_date
.
When I access the view, by default I want it only to show records who's dates are not expired.
Expired being defined as:
- End date and start date <= Now, and
- End date is later than the start date
I then want to have a checkbox that shows all records including the ones that have been expired.
How do I approach this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的控制器操作中,您希望将其放在某处:
您还可以绕过所有搜索内容,只使用如下范围:
In your controller action, you want to have this somewhere:
You could also bypass all the search things and just use a scope like this: