【发布时间】:2011-05-30 14:54:19
【问题描述】:
我想删除由user 拥有的嵌套对象book。在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方法在哪个控制器中?图书和用户有什么关系? -
要编辑问题。
-
谢谢。我现在明白你的问题了。
标签: ruby-on-rails ruby-on-rails-3 actioncontroller nested-resources