Winn.ws

visual_effect with a delay

Ruby on RailsOne of the coolest things I ran across in RJS was the delay method. This delay method will do just that and delay a number of seconds. So lets say you need to highlight something that was just added to the page after the user submits it. I would like it to add to the page then wait 1 second and then highlight. The following is the code for that.

[ruby]

render :update do |page|
page.html_replace ‘testdiv’, params[:the_text_added]

page.delay(1) do
page.visual_effect :highlight, ‘testdiv’, :duration => 2
end
end

[/ruby]

Cool huh? Try it out and see what you can do with delay()!

posted in: Development 03.01.08