Undefined method `product_shop_url'

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:increate’

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?

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

On Jan 6, 2008 8:27 PM, Xxx Y. [email protected]
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/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs