ruby on rails - Make a Mysql query that finds data just before another (in RoR) -


i'm making query mysql

image.find( :all,      :conditions => ["created_at > ? && approved = 1", @image.created_at],                             :order => "created_at desc", :limit => 5) 

however, want images create just before given image created at. right now, it's returning list of images top of list, create much, before image. how can this?

your current query find images newer @image because using >. you'll need decide kind of range you're wanting in.. time frame consider "just before"? minutes? seconds?

to find images created within 5 mins of @image, try:

image.find(:all, :conditions => ["(created_at > ? , created_at < ?) , approved = 1", @image.created_at.advance(:minutes => -5), @image.created_at])  

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -