Reputation: 1771
I have the following destroy method in my Tracks controller:
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
I can destroy a Release Track using:
<%= link_to 'Destroy', release_track_path(@release,track), :confirm => 'Are you sure?', :method => :delete %>
But I get a routing error " No route matches [POST] "/products/74/tracks/43" " when I try to destroy Product Track:
<%= link_to 'Destroy', product_track_path(@product,track), :confirm => 'Are you sure?', :method => :destroy %>
I've taken a look at my Routes file and think it's probably an issue there, but having tried a few things i'm stumped! Can anyone help? This is driving me crazy. I'm using the same if els on my create method and it works fine for both Release Track and Product Track.
Here's my routes.rb (I suspect this is a big mess!)
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
Upvotes: 0
Views: 941
Reputation: 26
In order to manage your controllers in a much more maintainable way, you should really checkout the ressource_controller. It hides all the standard stuff away and lets you concentrate on the stuff you want to customize.
Upvotes: 0
Reputation: 12235
You seem to have mixed up :delete and :destroy and the second line. :method expects an HTTP verb, so it should be :delete.
Upvotes: 2