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?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
You haven''t defined map.resources :shops, :member => { :product
=> :get } in
your routes.rb file.
On Jan 6, 2008 8:27 PM, Xxx Yyy
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:
>
> 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?
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
Ryan Bigg
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 Bigg wrote:> You haven''t defined map.resources :shops, :member => { :product => :get > } in > your routes.rb file.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---