开发者

Rails condition where days ago?

开发者 https://www.devze.com 2023-03-06 06:18 出处:网络
@messages = current_user.message_parti开发者_C百科cipantions.where(:read => false, :updated_at > 5.days.ago)
@messages = current_user.message_parti开发者_C百科cipantions.where(:read => false, :updated_at > 5.days.ago)

The updated_at 5 days ago errors. Do I need to use a format like so:

find(:all, :conditions => ["created_at > ?", 5.days.ago])


You could do:

@messages = current_user.message_participantions.where("read = ? AND updated_at > ?", false, 5.days.ago)

Or if for some reason you need to use the hash:

@messages = current_user.message_participantions.where(:read => false, :updated_at => 5.days.ago..Time.now)

As the values of the hash argument to the where method can be exact values or ranges: http://api.rubyonrails.org/classes/ActiveRecord/Base.html


@messages = current_user.message_participantions.where(:read => false).where("updated_at > ?", 5.days.ago)


I would:

@messages = current_user.message_participantions.where(["read = 0 AND updated_at > ?", 5.days.ago])
0

精彩评论

暂无评论...
验证码 换一张
取 消