私はRails 3を使用しています。私はメソッドを持つlink_toを持っています:delete、しかし、このリンクをクリックすると、代わりにshowアクションに行きます。リンクを削除する方法を表示するには
私の質問はこの問題を解決する方法ですか?
ありがとうございます。
コード:<%= link_to 'Delete', list_path(@list.id), :method => :delete, :confirm => 'Are you sure?' %>
私はRails 3を使用しています。私はメソッドを持つlink_toを持っています:delete、しかし、このリンクをクリックすると、代わりにshowアクションに行きます。リンクを削除する方法を表示するには
私の質問はこの問題を解決する方法ですか?
ありがとうございます。
コード:<%= link_to 'Delete', list_path(@list.id), :method => :delete, :confirm => 'Are you sure?' %>
あなたはあなたのapplication.js
ファイルに含まjquery
とjquery_ujs
のライブラリを持っていない、またはあなたもapp/views/layouts/application.html.erb
であなたのapplication.js
ファイルを含めていません。これは典型的には、この行で行われます。
<%= javascript_include_tag "application" %>
こんにちはあなたはこれを試すことができます。
application.html.erb:
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "jquery.rails.js" %>
とあなたのリンクのコードは次のようにする必要があります:
<%= link_to "<i class='icon-trash'></i> Delete".html_safe, item, :confirm => "Are you sure you want to delete item: " + item.name + "?" ,:method => :delete%>
あなたのコントローラーは次のようになります:
def destroy
@item = Item.find(params[:id])
if @item.destroy
redirect_to items_path, :notice => "Successfully deleted an item."
else
redirect_to items_path, :notice => "Failed to delete an item."
end
end
おそらくこのような質問をしたいと思うでしょう:http://stackoverflow.com/questions/3774925/delete-link-sends-get-instead-of-delete-in-rails-3-view –