# RESTful problems - \_url failed to generate

**URL:** <https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086>\
**Category:** Rails\
**Created:** [July 15, 2008, 3:25am UTC](https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086 "2008-07-15T03:25:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![validkeys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/da6949/32.png) [@validkeys](https://www.ruby-forum.com/u/validkeys)\
**Post date:** [July 15, 2008, 3:25am UTC](https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086/1 "2008-07-15T03:25:55Z")

</div>

Hey guys,

I am a noob, so hopefully this problem has an easy solution. I am  
building a simple shopping cart with products that have product  
categories.

I have set up my routes like the following:

map.resources :product\_categories do |product\_categories|  
product\_categories.resources :products  
end

which should get me /product\_categories/{:product\_category\_id}/  
products/{:id} (for example)

All of the paths seem to be working except when I click to edit a  
product. I am using the  
edit\_product\_category\_product\_path(@product\_category,@product) method  
in the link\_to. When I click to edit a product with this path, I get  
the following error message:

product\_category\_product\_url failed to generate from  
{:action=\>“show”, :product\_category\_id=\>#\<Product id: 2, name: “test  
2”, item\_number: “klagkljga”, price: #\<BigDecimal:2363a60,‘0.4323E2’,  
8(8)\>, description: “HEY!”, created\_at: “2008-07-15 00:41:02”,  
updated\_at: “2008-07-15 00:41:02”, product\_category\_id:  
1\>, :controller=\>“products”}, expected:  
{:action=\>“show”, :controller=\>“products”}, diff:  
{:product\_category\_id=\>#\<Product id: 2, name: “test 2”, item\_number:  
“klagkljga”, price: #BigDecimal:236223c,‘0.4323E2’,8(8),  
description: “HEY!”, created\_at: “2008-07-15 00:41:02”, updated\_at:  
“2008-07-15 00:41:02”, product\_category\_id: 1\>}

In my products controller, I have a private method:

private

def load\_product\_category  
@product\_category =  
ProductCategory.find(params[:product\_category\_id])  
end

which I call in before\_filter on the controller so that this instance  
variable is available to all actions

Does anyone have any ideas? I would really appreciate it!

---

<div class="post-metadata">

**Author:** ![validkeys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/da6949/32.png) [@validkeys](https://www.ruby-forum.com/u/validkeys)\
**Post date:** [July 15, 2008, 1:05pm UTC](https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086/2 "2008-07-15T13:05:03Z")

</div>

anyone?

---

<div class="post-metadata">

**Author:** ![validkeys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/da6949/32.png) [@validkeys](https://www.ruby-forum.com/u/validkeys)\
**Post date:** [July 16, 2008, 2:14am UTC](https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086/3 "2008-07-16T02:14:17Z")

</div>

How are you doing the link\_to?

---

<div class="post-metadata">

**Author:** ![validkeys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/da6949/32.png) [@validkeys](https://www.ruby-forum.com/u/validkeys)\
**Post date:** [July 16, 2008, 9:29am UTC](https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086/4 "2008-07-16T09:29:23Z")

</div>

Try this:  
edit\_product\_category\_product\_path(@product\_category.id,@product)

On Tue, Jul 15, 2008 at 5:14 PM, Andreh L. \<

---

<div class="post-metadata">

**Author:** ![validkeys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/da6949/32.png) [@validkeys](https://www.ruby-forum.com/u/validkeys)\
**Post date:** [July 17, 2008, 2:44pm UTC](https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086/5 "2008-07-17T14:44:57Z")

</div>

Sorry guys, for some reason i wasn’t getting email updates that anyone  
had posted anything here. Let me try these out and will let you know!  
Thanks for your help!

---

<div class="post-metadata">

**Author:** ![validkeys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/da6949/32.png) [@validkeys](https://www.ruby-forum.com/u/validkeys)\
**Post date:** [July 16, 2008, 3:32pm UTC](https://www.ruby-forum.com/t/restful-problems-url-failed-to-generate/143086/6 "2008-07-16T15:32:27Z")

</div>

I believe you can also just do:

url\_for [@product\_category, @product]

if you have your routes set up right. I do this sort of thing all the  
time fo nested restful routes:

\<%= link\_to h(@item.name), [@category, @item] %\>
