Rails:查找在某一天创建的任务? [英] Rails: Find tasks that were created on a certain day?

查看:40
本文介绍了Rails:查找在某一天创建的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个任务列表(名称、starts_at),我正在尝试在每日视图中显示它们(就像 iCal 一样).

I have a list of tasks (name, starts_at) and I'm trying to display them in a daily view (just like iCal).

def todays_tasks(day)
    Task.find(:all, :conditions => ["starts_at between ? and ?", day.beginning, day.ending]
end

我不知道如何将 Time.now(例如2009-04-12 10:00:00")动态转换为一天的开始(和结束),以便进行比较.

I can't figure out how to convert Time.now such as "2009-04-12 10:00:00" into the beginning (and end) of the day dynamically so I can make the comparison.

推荐答案

def todays_tasks(now = Time.now)
  Task.find(:all, :conditions => ["starts_at > ? AND < ?", now.at_beginning_of_day, now.at_end_of_day])
end

瞧!

这篇关于Rails:查找在某一天创建的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆