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?