在给定的时间戳后获取评论

Get comments after the timestamp given

我正在按照 Ryan 的教程轮询评论并完美运行,但在轮询数据时他使用 id 仅获取最新评论。如何使用时间戳仅轮询最新评论

这是模型、控制器、视图、coffeescript 的要点 link https://gist.github.com/silvercrow27/e08c0142af43aec39f02

您可以尝试这样的操作:

timestamp = 1432360568
Model.where(:updated_at => Time.at(timestamp))
# Model Load (20.4ms)  SELECT `models`.* FROM `models` WHERE `models`.`updated_at` = '2015-05-23 05:56:08'

假设评论属于 post 并且您想在给定时间戳后获取特定 post 的所有评论。这可以像这样完成:

Comment.where(:post_id => post.id).where("updated_at > ?", Time.at(timestamp))

如果你的意思是 created_at 作为时间戳那么你可以使用这样的东西

post = Post.order("created_at").last

获取最近创建的一个

post = Post.order("updated_at").last

获取最近更新的

Mongoid 你想要:

Post.where(:updated_at.gte => 1.hour.ago)

这将 return 您在过去一小时内更新的帖子。