以下呈现" 2"在表格提交时应该在div中。
完整品牌/ create.js.erb版本1:
$("#brand_ajax").html("1")
$("#brand_ajax").html("0")
$("#brand_ajax").html("2")
partial brands / show_brands.html.erb 我要刷新的div
<% for brand in @brands%>
ID: <%= h brand.id %>
<% end %>
partial cars / show.html.erb ajax调用
<%= form_for([@car, @car.brands.build], **remote: true**) do |f| %>
<%= f.fields_for :brandsdo |a| %>
<%= a.text_field :name, placeholder: "New Manufacturer" %>
<% end %>
<%= f.submit "+", class: "btn inline" %>
<% end %>
**/*The div I want to refresh*/**
<div id="brand_ajax">
<%= render 'brands/show_brands' %>
</div>
品牌控制器
respond_to do |format|
if @brand.save
format.html { redirect_to @car }
format.js
else
flash[:notice] = "Error!"
format.html { redirect_to @car }
end
end
以下内容未呈现&#34; 2&#34;提交新品牌表格后 - 根本不刷新。只显示旧版本 &#39; show_brands&#39;
完整品牌/ create.js.erb(以说明)
$("#brand_ajax").html("1")
$("#brand_ajax").html("<%= escape_javascript render 'show_brands' %>")
$("#brand_ajax").html("2")
为什么会发生这样的事情的任何想法?
答案 0 :(得分:0)
尝试
$("#brand_ajax").html("<%= j render :partial => 'show_brands' %>")