On 15 July 2010 08:50, Rob Nichols <[email protected]> wrote:
>...
> Oh! and to maximise the maintainability, I'd recommend splitting the
> queries out to their own methods:
>
> def last_state
>  self.states.find(:first, :order => "created_at")
> end
>
> def first_state_after(time)
>  self.states.find(:first, :conditions => ["created_at < ?", time],
> :order => "created_at desc")
> end
>
> first_state_after(time) || last_state

Or possibly even better as named_scopes (and I think a typo on the
names, they should be first_state, and last_state_before).

Colin
Colin

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to