How to reload a div using render(:update) and replace_html?

jbjuly picture jbjuly · Jul 13, 2010 · Viewed 8.8k times · Source

How to reload only the div id on a page? I just need to reload a certain div.

in my controller I have

def mycontrolleraction
 ...

 render(:update) do |page|
   reload_only_the_div('adiv'), :controller => 'my_controller'
 end

end

Is this possible?

Answer

dombesz picture dombesz · Jul 13, 2010

You can replace a div's content with a partial like this.

render :update do |page|
  page.replace_html 'person-45', :partial => 'person', :object => @person
end

Where the div id is person-45 the partial's name is person. Also you can pass an object to your partial, in this case the object is @person. For more information please see the documentation.