如何使用render(:update)和replace_html重新加载div? [英] How to reload a div using render(:update) and replace_html?

查看:197
本文介绍了如何使用render(:update)和replace_html重新加载div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅重新加载页面上的div ID? 我只需要重新加载某个div.

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

我的控制器中有

def mycontrolleraction
 ...

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

end

这可能吗?

推荐答案

您可以用这样的部分内容替换div的内容.

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

其中div ID为person-45的部分的名称为person.您也可以将对象传递给局部对象,在这种情况下,对象为@person.有关更多信息,请参见文档.

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.

这篇关于如何使用render(:update)和replace_html重新加载div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆