my new.js.erb like
$("#product1-modal").html("<%= escape_javascript(render 'new') %>")
$("#product1-modal").modal("show")
_new.html。动词like
<div class="modal-header">
<h3>New Product</h3>
</div>
<%= render "form" %>
和my _form.html.erb
<%= form_for @product1, remote: true, html: { class: "form-horizontal", style: "display:inline;" } do |f| %>
<div class="modal-body">
<ul class="errors"></ul>
<div class="control-group">
<%= f.label :name, class:"control-label" %>
<div class="controls">
<%= f.text_field :name %>
</div>
</div>
<div class="control-group">
<%= f.label :price, class: "control-label" %>
<div class="controls">
<%= f.text_field :price %>
</div>
</div>
</div>
<div class="modal-footer">
<%= f.submit class: "btn btn-primary" %>
<%= link_to "Cancel", "#", class: "btn", data: {dismiss: "modal"} %>
</div>
<% end %>
我的局部表单没有加载我得到的响应是看起来很好,但页面没有加载有人能帮我吗?
当我点击new button时我得到的是
$("#product1-modal").html("<div class="modal-header">n <h3>New Product</h3>n </div>n <form accept-charset="UTF-8" action="/product1s" class="form-horizontal" data-remote="true" id="new_product1" method="post" style="display:inline;"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="mUNwn0fJoZ4lCbJjy8Ju8V78xp+/mjXoZkoqbh0EeOw=" /></div>n <div class="modal-body">n <ul class="errors"></ul>n n <div class="control-group">n <label class="control-label" for="product1_name">Name</label>n <div class="controls">n <input id="product1_name" name="product1[name]" size="30" type="text" />n </div>n </div>n <div class="control-group">n <label class="control-label" for="product1_price">Price</label>n <div class="controls">n <input id="product1_price" name="product1[price]" size="30" type="text" />n </div>n </div>n </div>n <div class="modal-footer">n <input class="btn btn-primary" name="commit" type="submit" value="Create Product1" />n <a href="#" class="btn" data-dismiss="modal">Cancel</a>n </div>n</form>n")
$("#product1-modal").modal("show")
index.html.erb
<div class="container">
<div class="well">
<%= link_to "New Product1", new_product1_path, remote: true, class: "btn btn-primary" %>
</div>
<div class="new-product1"></div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<td> </td>
<td> </td>
</tr>
</thead>
<tbody class="product1-index">
<%= render "index" %>
</tbody>
</table>
</div>
<div id="product1-modal" class="modal hide fade"></div>
看起来你给错了id
在你的new.js.erb文件中应该是'#product-modal'而不是'#product1-modal'
$("#product-modal").html("<%= escape_javascript(render 'new') %>")
$("#product-modal").modal("show")
更新new.js.erb文件
可能不是这样,但是如果在new.js中没有分号。动词,这可能会导致问题
如果没有,尝试添加它们。
$("#product1-modal").html("<%= escape_javascript(render 'new') %>");
$("#product1-modal").modal("show");