在我看来af_form.html.erb
我有一个用于触发 ajax 调用的按钮
<%= button_to('update ', {:action => 'update', :thingyid => 314}, :method => :get, :remote => true , :'data-update-target' => 'af_stat' ) %>
<div id="af_stat" >
<h3>Tiltle :
<%= @kk %>
</h3>
有人说我应该有一个名为 _af_form.html.erb 的文件,_af_form.html.erb 应该是什么?
在我的 Controller welcome 中,有一个方法
def update
@kk = @kk +1
render :partial => 'af_form', :content_type => 'text/html'
end
我听到有人说...“和 af_form.js.erb 一样”?这不是愚蠢吗?复制两个相同的文件。并违反 DRY 规则。
它不起作用。怎么了。 任何人都可以帮助我。非常感谢。
我只想改变 View af_form.html.erb 不是 _af_form.html.erb ,为什么我需要 _af_form.html.erb
最佳答案
在你的 update.js.erb
中试试这个
$('#af_stat h3').text('Title: <%= escape_javascript @kk %>');
关于ruby-on-rails - 在 Rails 中使用 Ajax 更新 Div 而无需重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15080887/