I want to delete the nested object book, that is owned by a user. In the user#show page appears all the books related to that user. Besides each book there is a link to delete it. Here is my code:
routes.rb:
resources :users do
resources :books, :only => [:new, :create, :destroy]
end
book_controller.rb:
def destroy
@user= User.find(params[:user])
@book = Book.find(params[:book])
@book.destroy
redirect_to current_user
end
And in the user#show page:
<%= link_to "Delete", user_book_path(current_user, book), :method => :delete %>
I know this is wrong, but how can I do it in order to deleted the wanted book?