Rails nested resource with response_with destroy action

What is the appropriate respond_with line to destroy nested resources?

My routes:

 resources :vendors do resources :products, :except => [:index] end 

# @vendor product ( @vendor and @product found with before_filter , which is omitted here)

 def destroy @product.destroy respond_with @vendor, @product end 

According to my functional tests, this returns /vendors/X/products/X , not /vendors/X

Should I change it to responed_to @vendor ?

+3
source share
2 answers

I believe Rails is smart enough to figure out what to do if @product is destroyed

 respond_with [@vendor, @product] 

If not, try this one.

 respond_with @product, :location => vendor_path(@vendor) 
+5
source

Sorry, this answer was completely wrong (misunderstood your problem):

Your destruction code may be as follows:

 def destroy @product = Product.find(params[:id]) @product.destroy redirect_to <route method for vendor products index>, :notice => 'Any message' end 

See the exact route routing routes in your terminal.

params [: vendor_id] should also be available.

+2
source

All Articles