加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何在rails 4中使用page.replace_html

发布时间:2020-12-16 21:00:59 所属栏目:百科 来源:网络整理
导读:嗨,目前我正在将我的项目从rails 3.2升级到rails 4.升级到rails 4. page.replace_html方法不起作用属性. 例如: 在控制器中如果遇到这样的代码, render :update do |page| page.replace_html “lease_container”,:partial = “/lease/property_pipeline”,:
嗨,目前我正在将我的项目从rails 3.2升级到rails 4.升级到rails 4. page.replace_html方法不起作用属性.

例如:

在控制器中如果遇到这样的代码,

render :update do |page|

page.replace_html “lease_container”,:partial =>
“/lease/property_pipeline”,:locals => {:note_collection => @note}

end

它抛出这样的错误,

ActionView::MissingTemplate (Missing template lease/update,
application/update with {:locale=>[:en],:formats=>[:js,:html,:xml,
:html,:text,:js,:css,:ics,:csv,:png,:jpeg,:gif,:bmp,:tiff,
:mpeg,:rss,:atom,:yaml,:multipart_form,:url_encoded_form,
:json,:pdf,:zip],:handlers=>[:erb,:builder,:raw,:ruby,:rjs]}

我怎么能解决这个问题?有什么替代方法可以用jquery做到这一点吗?

解决方法

使用 prototype-rails助手宝石

更好的是,重构代码以使用jQuery. Rails现在鼓励使用UJS(Un Obtrusive JavaScript).因此,jQuery中的确切替换语法可能并不可取.

你可以尝试这样的事情

$("#divid").html("<div>all the html goes here</div>")

这将替换< div id =“divid”> ….< / div>的内容将什么传递给.html(“….”)

这是jQuery documentation for .html()

这个主题有一个很好的RailsCasts Episode #205

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读