Quantcast
Channel: Rails 3 - Nested Resources - Routing - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Jaime Bellmyer for Rails 3 - Nested Resources - Routing

$
0
0

order_products_url expects a parameter to be passed - either the order id, or the order object itself. Without this, it won't work properly. So using your code above:

def destroy    @product = Product.find(params[:id])    @order = Order.find(params[:order_id])    @product.destroy    respond_to do |format|      format.html { redirect_to(order_products_url(@order) }      format.xml  { head :ok }    endend

As a side note, you can shorten your routes a little:

resources :orders do  resources :productsend

Specifying the controller is redundant when it's named as Rails expects. I hope this helps!

UPDATE: I've added a link to my article about routing in Rails 3, with downloadable code samples. I updated it with a paragraph that explains named routes, in the "Things You Should Know" section:

Routing in Ruby on Rails 3


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>