I have a model User and a model message.viewed_at
What I want to do is given a user, determine when they last viewed a message if ever.
Given the user, I need to find all there messages, and then sort by the most recent viewed_at at the top, and then take that record and output the viewed_at timestamp if any.
@user = User.find(2)
@user.find(:first, :conditions => user.messages.viewed_at != nil)
But that doesn’t work, suggestions? Thanks
@user.messages.first(:order => "viewed_at desc")Here are the docs.
@user.messages.where("viewed_at is not null").order("viewed_at desc").first