I can find last record in my table like in example below, but what if I want to find record before last, e.g. (last-1) or (last-2)..? I have this example in my each loop:
Table.find(:last, :conditions => {:dogovor_id => p.id}).id
Another easier to remember way is: Model.last(2).first
Table.where(:dogovor_id => p.id).order("id DESC").first # last
Table.where(:dogovor_id => p.id).order("id DESC").offset(1).first # last - 1
Table.where(:dogovor_id => p.id).order("id DESC").offset(2).first # last - 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With