views:

39

answers:

1

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.

A: 

Your solution could be as simple as removing the element that you faded.

My guess is the fade visual effect hides the element but doesn't remove it from the DOM, so what ends up happening is you will continue to fade the same element which obviously doesn't do anything.

Karl