How do I find the object with the oldest updated_at column in RJS?

Posted by user284194 on Stack Overflow See other posts from Stack Overflow or by user284194
Published on 2010-03-10T18:46:09Z Indexed on 2010/03/11 5:58 UTC
Read the original article Hit count: 314

Filed under:
|
|
|
|

Hello, I'm trying to remove the object with the oldest updated_at value when the rjs is executed.

page.insert_html :top, :messages, :partial => @message
page[@message].visual_effect :grow
page[:message_form].reset
Message.old_messages.each do |m|
  page.remove(m.id)
end
page.delay(1) do 
  page.select('.message').last.visual_effect :fade
end

I'm using .last in there right now, but I have a periodically_call_remote in the view that continually updates and runs the rjs above. The line:

page.select('.message').last.visual_effect :fade

seems to only execute the first time because after the message that is "last" fades away there's nothing recognized as "last" anymore so I figure instead of calling .last I could find the object that has the oldest updated_at time stamp and just remove that instead. I'm thinking that I probably cannot do this using page.select since it only calls on css elements. And therefore I probably don't have access to the updated_at values in the Message model. Does anyone have a suggestion on how to accomplish removing the oldest message with rjs? The messages are already automatically removed in the model as new messages are created. But I want them to fade automatically when the RJS refreshes the element.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby