嗨,目前我正在将我的项目从 rails 3.2 升级到 rails 4。升级到 rails 4 后。page.replace_html
方法不是工作属性。
例如:
在 Controller 中,如果遇到这样的代码,
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, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :raw, :ruby, :rjs]}
我怎么能解决这个问题?有没有其他方法可以用 jquery 做到这一点?
最佳答案
使用 prototype-rails辅助 gem
更好的是,重构代码以使用 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关于这个话题
关于ruby-on-rails - 如何在 Rails 4 中使用 page.replace_html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19837002/