Ruby on Rails Friday, June 1, 2012

I have a situation where a code can be toggled on/off so a record is
sent to database with a value of 1 or 2 for code. So lets say it was
toggled 4 times:

id, code, time
1, 1, 2012-05-31 22:05:24
2, 2, 2012-05-31 22:05:25
3, 2, 2012-05-31 22:05:26
4, 2, 2012-05-31 22:05:27


So it was toggled on once and toggled off 3 times.

Now I would like to use rails 3 in order to find the last record
toggled to off and the last record toggled to on.

Something like this below, but this would pull the last two records
that meet either criteria, which is not what I want:

where{code.in([1, 2])}.order('time desc').limit(2)

thanks for response

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment