Rails 3 destroy method respond_with JS using nested resources
-
30-10-2019 - |
문제
I'm having this annoying problem with Rails 3 (ruby 1.9.2) and nested resources. In my routes:
resources :lists do
resources :items, only: [:destroy, :update, :create]
end
My ItemsController
has respond_to :json
at the beginning and #destroy
looks like this:
def destroy
@item = Item.find(params[:id])
@item.destroy
respond_with @list, @item
end
The link to destroy the item:
<%= link_to 'x', list_item_path(@list, item), method: :delete, remote: true %>
Which translates into correct html, like:
<a href="/lists/1/items/52" data-method="delete" data-remote="true" rel="nofollow">x</a>
When I click the link, my item is correctly deleted but the method always returns {}
. I've been trying to tinker with it but can't get anything different from that empty JSON object!
Every other method (#create
and #update
) works and returns JSON objects as expected.
올바른 솔루션이 없습니다
제휴하지 않습니다 StackOverflow