# Undefined method \`product\_shop\_url'

**URL:** <https://www.ruby-forum.com/t/undefined-method-product-shop-url/125153>\
**Category:** Rails\
**Created:** [January 6, 2008, 10:57am UTC](https://www.ruby-forum.com/t/undefined-method-product-shop-url/125153 "2008-01-06T10:57:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![heyho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a183cd/32.png) [@heyho](https://www.ruby-forum.com/u/heyho)\
**Post date:** [January 6, 2008, 10:57am UTC](https://www.ruby-forum.com/t/undefined-method-product-shop-url/125153/1 "2008-01-06T10:57:26Z")

</div>

Hi,

I created a new table in my project which represents a m:n-relation:

create table products\_shops (  
id int not null auto\_increment,  
product\_id int not null,  
shop\_id int not null,  
constraint fk\_productsshops\_products foreign key (product\_id)  
references products(id),  
constraint fk\_productsshops\_shops foreign key (shop\_id) references  
shops(id),  
primary key(id)  
) engine=InnoDB;

Afterwards I called “scaffold\_resource” with “product\_shop id:int  
product\_id:int shop\_id:int”.

Now I tried to run the tests. The Unittest is fine, but in the  
functional test the following error occurs:  
test\_should\_create\_product\_shop(ProductsShopsControllerTest):  
NoMethodError: undefined method `product_shop_url' for #<ProductsShopsController:0x45ce7a8> /app/controllers/products_shops_controller.rb:42:in`create’

The effected code snippets are:

class ProductsShopsControllerTest \< Test::Unit::TestCase  
…

def test\_should\_create\_product\_shop  
old\_count = ProductShop.count  
post :create, :product\_shop =\> {:product\_id =\> 1, :shop\_id =\> 1}  
assert\_equal old\_count+1, ProductShop.count

```
assert_redirected_to product_shop_path(assigns(:product_shop))

```

end

…  
end

class ProductsShopsController \< ApplicationController  
…

def create  
@product\_shop = ProductShop.new(params[:product\_shop])

```
respond_to do |format|
  if @product_shop.save
    flash[:notice] = 'ProductShop was successfully created.'
    format.html { redirect_to product_shop_url(@product_shop) }
    format.xml { head :created, :location =>

```

product\_shop\_url(@product\_shop) }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @product\_shop.errors.to\_xml }  
end  
end  
end

…  
end

I’m quite new to Ruby on Rails and I do not even know, where I can find  
the implementation of product\_shop\_url. I mean, I have another class,  
e.g. ProductsController, where product\_url is called and there I do not  
get an error, but I can’t find method product\_url either. Can you tell  
me how it works and do you have an idea why this error occurs?

---

<div class="post-metadata">

**Author:** ![heyho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a183cd/32.png) [@heyho](https://www.ruby-forum.com/u/heyho)\
**Post date:** [January 7, 2008, 2:41am UTC](https://www.ruby-forum.com/t/undefined-method-product-shop-url/125153/2 "2008-01-07T02:41:59Z")

</div>

You haven’t defined map.resources :shops, :member =\> { :product =\> :get  
} in  
your routes.rb file.

On Jan 6, 2008 8:27 PM, Xxx Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## references products(id), test\_should\_create\_product\_shop(ProductsShopsControllerTest): old\_count = ProductShop.count class ProductsShopsController \< ApplicationController product\_shop\_url(@product\_shop) } I’m quite new to Ruby on Rails and I do not even know, where I can find the implementation of product\_shop\_url. I mean, I have another class, e.g. ProductsController, where product\_url is called and there I do not get an error, but I can’t find method product\_url either. Can you tell me how it works and do you have an idea why this error occurs?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![heyho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a183cd/32.png) [@heyho](https://www.ruby-forum.com/u/heyho)\
**Post date:** [January 7, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/undefined-method-product-shop-url/125153/3 "2008-01-07T20:26:08Z")

</div>

Thank you very much for ya quick answer! It works. Now I try to  
understand that routing-thing… But I think I find enough documentation  
about that - now that I know what I have to look for. Thanks!

Ryan B. wrote:

> You haven’t defined map.resources :shops, :member =\> { :product =\> :get  
> } in  
> your routes.rb file.
