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

二次信任 提交于 2019-11-30 19:03:25

问题


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?


回答1:


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.




回答2:


ref ajax-on-rails tutorial.To replace the html content of some div use replace_html

render :update do |page|
  replace_html 'div', 'new refresh data'
end



回答3:


use partials to update particular div in view

render :partial => "fileame", :layout => false


来源:https://stackoverflow.com/questions/3235315/how-to-reload-a-div-using-renderupdate-and-replace-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!