我想删除嵌套对象book
,它由user
拥有。在user#show
页面出现所有与user
相关的books
。除了每本书,还有一个链接到delete
它。这里是我的代码:导轨 - 嵌套对象删除
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
而在user#show
页:
<%= link_to "Delete", user_book_path(current_user, book), :method => :delete %>
我知道这是错的,但我怎么能这样做是为了删除通缉书吗?
你向我们展示的代码并没有太大的意义。在哪个控制器中是'destroy'方法?书和用户有什么关系? – Mischa 2011-05-30 15:05:44
要编辑问题。 – Samth 2011-05-30 15:08:22
谢谢。我现在明白你的问题。 – Mischa 2011-05-30 15:16:43