我需要查询在一天提出的意见。本场是标准时间戳的一部分,是created_at。选定的日期是从date_select到来。我如何使用ActiveRecord来做到这一点?
我需要财产以后这样的:
SELECT * FROM评论WHERE created_at'之间2010-02-03 00:00:00和23:59:59 2010-02-03'
解决方案
只是说明了目前公认的答案是德precated用Rails 3。你应该这样做,而不是:
Comment.where(:created_at => @ selected_date.beginning_of_day .. @ selected_date.end_of_day)
I need to query comments made in one day. The field is part of the standard timestamps, is created_at. The selected date is coming from a date_select. How can I use ActiveRecord to do that?
I need somthing like:
"SELECT * FROM comments WHERE created_at BETWEEN '2010-02-03 00:00:00' AND '2010-02-03 23:59:59'"
解决方案
Just a note that the currently accepted answer is deprecated in Rails 3. You should do this instead:
Comment.where(:created_at => @selected_date.beginning_of_day..@selected_date.end_of_day)
上一篇:怎么办阿雷尔和Rails一个LIKE查询?雷尔、Rails、LIKE
下一篇:如何处理Ruby on Rails的错误:"请安装PostgreSQL的适配器:`安装了activerecord-PostgreSQL的适配器“"适配器、如何处理、错误、安装了