我的Tracks控制器中有以下destroy方法:
def destroy
if params[:product_id].present?
@product = Product.find(params[:product_id])
@track = @product.tracks.find(params[:id])
@track.destroy
redirect_to product_path(@product)
elsif params[:release_id].present?
@release = Release.find(params[:release_id])
@track = @release.tracks.find(params[:id])
@track.destroy
redirect_to release_path(@release)
end
end
我可以使用以下命令销毁发行曲目:
<%= link_to 'Destroy', release_track_path(@release,track), :confirm => 'Are you sure?', :method => :delete %>
但是当我试图破坏产品追踪时,我收到路由错误“没有路由匹配[POST]”/ products / 74 / tracks / 43“”
<%= link_to 'Destroy', product_track_path(@product,track), :confirm => 'Are you sure?', :method => :destroy %>
我看了一下我的Routes文件并认为这可能是一个问题,但尝试了一些我难倒的东西!有人可以帮忙吗?这真让我抓狂。我在创建方法上使用相同的if,并且它适用于Release Track和Product Track。
这是我的routes.rb(我怀疑这是一个很大的混乱!)
Dashboard::Application.routes.draw do
get "home/index"
root :to => "home#index"
get "tracks/new"
get "tracks/create"
get "tracks/update"
get "tracks/edit"
get "tracks/destroy"
get "tracks/show"
get "tracks/index"
get "help/index"
resources :helps
resources :roles
resources :labels
devise_for :users
resources :users
resources :releases do
resources :artists
resources :tracks
resources :products do
resources :tracks
resources :itunes_data
end
end
resources :itunes_data
resources :tracks do
collection { post :sort }
end
resources :products do
resources :tracks
collection do
get 'schedulecsv'
get 'schedule'
get 'new_releases'
get 'active_lines'
get 'deleted_lines'
get 'gemsetup'
get 'amazonsetup'
get 'search'
end
end
resources :artists
end
答案 0 :(得分:2)
你好像混淆了:删除和:破坏和第二行。 :method需要一个HTTP动词,所以它应该是:delete。
答案 1 :(得分:0)
为了以更易于维护的方式管理您的控制器,您应该真正检查ressource_controller。它隐藏了所有标准内容,让您专注于想要自定义的内容。