部分未加载rails-jquery

时间:2014-03-18 11:34:44

标签: javascript jquery ruby-on-rails ruby ruby-on-rails-3

我的new.js.erb就像

$("#product1-modal").html("<%= escape_javascript(render 'new') %>")
$("#product1-modal").modal("show")

_new.html.erb like

 <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=\"&#x2713;\" /><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>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</thead>
<tbody class="product1-index">
<%= render "index" %>
</tbody>
</table>
</div>
<div id="product1-modal" class="modal hide fade"></div>

2 个答案:

答案 0 :(得分:0)

看起来你提供了错误的身份

它应该是&#39; #product-modal&#39;而不是&#39; #product1-modal&#39;在你的new.js.erb文件中

$("#product-modal").html("<%= escape_javascript(render 'new') %>")
$("#product-modal").modal("show")

更新你的new.js.erb文件

答案 1 :(得分:0)

可能不是这个,但如果你的new.js.erb中没有分号,那可能会导致问题

如果没有,请尝试添加它们。

$("#product1-modal").html("<%= escape_javascript(render 'new') %>");
$("#product1-modal").modal("show");