method
replace_html

v3.0.9 -
Show latest stable
-
1 note -
Class: ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods
- 1.0.0
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (7)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
replace_html(id, *options_for_render)
public
Replaces the inner HTML of the DOM element with the given id.
options_for_render may be either a string of HTML to insert, or a hash of options to be passed to ActionView::Base#render. For example:
# Replace the HTML of the DOM element having ID 'person-45' with the # 'person' partial for the appropriate object. # Generates: Element.update("person-45", "-- Contents of 'person' partial --"); page.replace_html 'person-45', :partial => 'person', :object => @person
Register or
log in
to add new notes.
marcelo_murad -
July 5, 2009

2 thanks
To verify if the element exists before replacing.
Just add this code into a initializer file.
Atention: The code starts at the “module ActionView” and the last “end” has to be copied too.
module ActionView
module Helpers module PrototypeHelper class JavaScriptGenerator #:nodoc: module GeneratorMethods def replace_html_if_exists(id, *options_for_render) call "if($('#{id}')) Element.update", id, render(*options_for_render) end end end end end
end