AnA*_*ice 2 ruby-on-rails ruby-on-rails-3
@messages = current_user.message_participantions.where(:read => false, :updated_at > 5.days.ago)
Run Code Online (Sandbox Code Playgroud)
updated_at 5天前错误.我需要使用这样的格式:
find(:all, :conditions => ["created_at > ?", 5.days.ago])
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
@messages = current_user.message_participantions.where("read = ? AND updated_at > ?", false, 5.days.ago)
或者,如果由于某种原因您需要使用哈希:
@messages = current_user.message_participantions.where(:read => false, :updated_at => 5.days.ago..Time.now)
由于where方法的哈希参数的值可以是精确的值或范围:http://api.rubyonrails.org/classes/ActiveRecord/Base.html
@messages = current_user.message_participantions.where(:read => false).where("updated_at > ?", 5.days.ago)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4042 次 |
| 最近记录: |