[英]partial not loaded rails-jquery
我的new.js.erb就像
$("#product1-modal").html("<%= escape_javascript(render 'new') %>")
$("#product1-modal").modal("show")
_new.html.erb喜欢
<div class="modal-header">
<h3>New Product</h3>
</div>
<%= render "form" %>
和我的_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 %>
我的部分表单未加载我得到的响应很好,但未加载的页面可以帮助我吗?
当我单击新的按钮响应时,我得到的是
$("#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.erb中没有分号,则可能会导致问题
如果没有,请尝试添加它们。
$("#product1-modal").html("<%= escape_javascript(render 'new') %>");
$("#product1-modal").modal("show");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.