Search code examples
ruby-on-railsrjs

Updating an element with RJS


I have an 'Save' button on my application, which saves a record via AJAX once edited. That code is working lovely. I have discovered a little bug though. If I click the save button, eventually the code below is invoked:

page.replace_html "status-#{@restriction.id}", "Saved."
page.delay(2) do
  page.visual_effect :fade, "status-#{@restriction.id}"
end

If I change the value in the field again, and click 'Save', the value is saved correctly, however the 'Saved.' message as above does not show. How can I make it re-appear?

Thanks in advance, and my apologies if I've been stupid.

Gav


Solution

  • Try using the following as your first line:

    page["status-#{@restriction.id}"].show
    

    This should ensure that your DOM element is visible.