rails ajaxでテーブル行を削除しようとしています。しかし、私は私のコンソールで以下のエラーを取得しています。ajaxとレールでテーブルレコードを削除する際に404エラーが見つかりません
DELETE http://localhost:3000/spares 404 (Not Found)
以下は私のコードブロックです。
<%= link_to 'Destroy', spare, method: :delete, data: { confirm: "Are you sure you want to delete the #{spare.name}?" }, class: "btn btn-danger btn-xs",remote: true %></td>
destroy.js.erbファイル
//$('tr #<%= @spare.id %>').slideUp();
var element = document.getElementById(<%= @spare.id %>);
alert(element);
alert(hello);
element.parentNode.removeChild(element);
**上記のコードでアラートも表示されません。
<% @spares.each_with_index do |spare, index| %>
<tr id="li_<%= spare.id %>">
<td><%= index + 1 %></td>
<td><%= spare.name %></td>
<!-- authorization check -->
<% if can? :show, Spare %>
<td><%= link_to 'Show', spare, class: "btn btn-warning btn-xs" %>
<% end %>
<!-- authorization check -->
<% if can? :edit, Spare %>
<%= link_to 'Edit', edit_spare_path(spare), class: "btn btn-primary btn-xs" %>
<% end %>
<!-- authorization check -->
<% if can? :destroy, Spare %>
<%= link_to 'Destroy', spare, method: :delete, data: { confirm: "Are you sure you want to delete the #{spare.name}?" }, class: "btn btn-danger btn-xs",remote: true %></td>
私はレールパネルでレンダリングされているフォーマットをチェックし、それはJSを示しています**
以下は私のテーブルです。しかしレンダリングではdestroy.js.erbが表示されません。以下は
サーバログ
"/spares" for 127.0.0.1 at 2016-05-26 09:02:29 +0530
ActionController::RoutingError (No route matches [DELETE] "/spares"):
「<%= @ spare.id%>」はおそらく文字列ではなく整数を返します。 '<%= @ spare.id.to_s%>'を試してください。 –
申し訳ありませんが、それは助けませんでした。警告も表示されないので、destroy.js.erbファイル自体はレンダリングされません。 –
私はサーバログエラー –