Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Rails&;jQuery&;AJAX_Jquery_Ruby On Rails - Fatal编程技术网

使用Rails&;jQuery&;AJAX

使用Rails&;jQuery&;AJAX,jquery,ruby-on-rails,Jquery,Ruby On Rails,我在一个页面上有多张优惠券,我正试图获得对每张优惠券的评论。因此,对于每张优惠券,我都有一张评论表。我使用jQuery+Ajax来完成这个任务。下面是我的代码 优惠券页 <p>Comments:</p> <% form_for(@comment) do |f| %> <%= f.label :body %><br /><%= f.text_field :body, :size => "24" %>

我在一个页面上有多张优惠券,我正试图获得对每张优惠券的评论。因此,对于每张优惠券,我都有一张评论表。我使用jQuery+Ajax来完成这个任务。下面是我的代码

优惠券页

 <p>Comments:</p>
  <% form_for(@comment) do |f| %>
    <%= f.label :body %><br /><%= f.text_field :body, :size => "24"  %>
    <%= f.hidden_field :coupon_id, :value => coupon.id %>
    <%= f.submit "Save" %> 
  <% end %>
我尝试将jQuery选择器更改为类

$(".new_comment").submitWithAjax();
考虑到这一点,现在所有的提交按钮都可以工作,但是它只在页面上发布第一个表单

我可以做些什么更改,使ajax提交正确的表单而不是第一个表单

呈现的html是这样的:

<form action="/comments" class="new_comment" id="new_comment" method="post">
  <div style="margin:0;padding:0;display:inline">
    <input name="authenticity_token" type="hidden" value="b2ToPsRqJ+aXvh/W1pCpWrOlX010aruhku7alWoUSSg=" /></div> 
    <table> 
      <tr> 
        <td width="260px"> 
          <label for="comment_body">Body</label><br />
          <input id="comment_body" name="comment[body]" size="24" type="text" />
        </td> 
      </tr>
    </table> 
  <input id="comment_coupon_id" name="comment[coupon_id]" type="hidden" value="1790" /> 
  <input id="comment_submit" name="commit" type="submit" value="Save" />
</form>

正文

您可以发布呈现的HTML的外观吗?Body
您可以发布呈现的HTML的外观吗?正文
<form action="/comments" class="new_comment" id="new_comment" method="post">
  <div style="margin:0;padding:0;display:inline">
    <input name="authenticity_token" type="hidden" value="b2ToPsRqJ+aXvh/W1pCpWrOlX010aruhku7alWoUSSg=" /></div> 
    <table> 
      <tr> 
        <td width="260px"> 
          <label for="comment_body">Body</label><br />
          <input id="comment_body" name="comment[body]" size="24" type="text" />
        </td> 
      </tr>
    </table> 
  <input id="comment_coupon_id" name="comment[coupon_id]" type="hidden" value="1790" /> 
  <input id="comment_submit" name="commit" type="submit" value="Save" />
</form>