Subject: Chapter 1 Page 18 no errors
Posted By: zuufuzu Post Date: 4/17/2008 7:53:04 AM
Hello all!

I tried to go through Chapter 1 and I am not a Rails professional and bought the book because I am interessted in the professional point of view (real life). So may be this is a quite silly question? But after doing all this:

rails -d mysql soupsonline
cd soupsonline
ruby script/generate scaffold recipe title:string servings:string description:string directions:string
ruby script/generate scaffold ingredient recipe_id:integer order_of:integer amount:float ingredient:string instruction:string unit:string

#open config/routes.rb and add:
  map.resources :recipes do |recipes|
    recipes.resources :ingredients
  end
#

rake db:create:all
rake db:migrate
rake db:test:prepare

#now the tests:

C:\InstantRails-2.0-win\rails_apps\soupsonline>rake
(in C:/InstantRails-2.0-win/rails_apps/soupsonline)
C:/InstantRails-2.0-win/ruby/bin/ruby -Ilib;test "C:/InstantRails-2.0-win/ruby/l
ib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb" "test/unit/ingred
ient_test.rb" "test/unit/recipe_test.rb"
Loaded suite C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/
rake/rake_test_loader
Started
..
Finished in 0.14 seconds.

2 tests, 2 assertions, 0 failures, 0 errors
C:/InstantRails-2.0-win/ruby/bin/ruby -Ilib;test "C:/InstantRails-2.0-win/ruby/l
ib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb" "test/functional/
ingredients_controller_test.rb" "test/functional/recipes_controller_test.rb"
Loaded suite C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/
rake/rake_test_loader
Started
..............
Finished in 0.562 seconds.

14 tests, 26 assertions, 0 failures, 0 errors
C:/InstantRails-2.0-win/ruby/bin/ruby -Ilib;test "C:/InstantRails-2.0-win/ruby/l
ib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb"

C:\InstantRails-2.0-win\rails_apps\soupsonline>

#no errors here?

Ok, I think anywhere one has to tell the application that there is no ingredient without a recipe (1:n). But I can not figure out where (may be this RESTfullness and routes stuff that I am really not understanding completely so far is the reason). And after reading the Chapter again and again i think I need a little hint.

Thank you,

zuufuzu.

Reply By: noelrap Reply Date: 4/17/2008 9:20:39 AM
The nested route change should break tests all by itself, since it will change the names of the methods for generating URLs -- if you've done the changes on pages 18-20, then the test changes should be fixed.

If you run the command

rake routes

does your output show the nested route URLs?

Does your Ingredient model class have a line

belongs_to :recipe

Are you able to move forward with the rest of the chapter?

Let me know and we'll get to the bottom of this

Thanks,

Noel
Reply By: zuufuzu Reply Date: 4/17/2008 11:59:21 AM
Hello Noel,

thank you, for the imediate response!

quote:
Originally posted by noelrap

The nested route change should break tests all by itself, since it will change the names of the methods for generating URLs -- if you've done the changes on pages 18-20, then the test changes should be fixed.

If you run the command

rake routes


does your output show the nested route URLs?

zuufuzuu: i did: rake routes >routes.txt
#which gives:

(in C:/InstantRails-2.0-win/rails_apps/soupsonline)
                     ingredients GET    /ingredients                                     {:action=>"index", :controller=>"ingredients"}
           formatted_ingredients GET    /ingredients.:format                             {:action=>"index", :controller=>"ingredients"}
                                 POST   /ingredients                                     {:action=>"create", :controller=>"ingredients"}

 ...

GET    /recipes/:recipe_id/ingredients/new              {:action=>"new", :controller=>"ingredients"}
 formatted_new_recipe_ingredient GET    /recipes/:recipe_id/ingredients/new.:format      {:action=>"new", :controller=>"ingredients"}
          edit_recipe_ingredient GET    /recipes/:recipe_id/ingredients/:id/edit         {:action=>"edit", :controller=>"ingredients"}
formatted_edit_recipe_ingredient GET    /recipes/:recipe_id/ingredients/:id/edit.:format {:action=>"edit", :controller=>"ingredients"}
               recipe_ingredient GET    /recipes/:recipe_id/ingredients/:id              {:action=>"show", :controller=>"ingredients"}
     formatted_recipe_ingredient GET    /recipes/:recipe_id/ingredients/:id.:format      {:action=>"show", :controller=>"ingredients"}
                                 PUT    /recipes/:recipe_id/ingredients/:id              {:action=>"update", :controller=>"ingredients"}
                                 PUT    /recipes/:recipe_id/ingredients/:id.:format      {:action=>"update", :controller=>"ingredients"}
                                 DELETE /recipes/:recipe_id/ingredients/:id              {:action=>"destroy", :controller=>"ingredients"}
                                 DELETE /recipes/:recipe_id/ingredients/:id.:format      {:action=>"destroy", :controller=>"ingredients"}
                                        /:controller/:action/:id                         
                                        /:controller/:action/:id.:format                 
#looks ok


Does your Ingredient model class have a line

belongs_to :recipe

zuufuzu: No it has not! (But I think this should be generated, or have i, to do this by hand?)

Are you able to move forward with the rest of the chapter?

zuufuzuu: I can not go forward, cause all these lines to change are not there. Example: in test/functional there is only a "require File.dirname(__FILE__) + '/../test_helper'" which does itself:   fixtures :all

My environment:

Ruby version 1.8.6 (i386-mswin32)
RubyGems version 1.0.1
Rails version 2.0.2
Active Record version 2.0.2
Action Pack version 2.0.2
Active Resource version 2.0.2
Action Mailer version 2.0.2
Active Support version 2.0.2
Application root C:/InstantRails-2.0-win/rails_apps/soupsonline
Environment development
Database adapter mysql
Database schema version 2

I thought by adding

#open config/routes.rb and add:
  map.resources :recipes do |recipes|
    recipes.resources :ingredients
  end
#

the rest (i mean the errors) is automatic. But something does not work. (I tried the same thing on a virtual Ubuntu Server with the same enviroment (versions). Everything is equal.)



Let me know and we'll get to the bottom of this



Thanks,

Noel



Reply By: noelrap Reply Date: 4/17/2008 12:04:12 PM
Okay, here's a wild guess -- do you still have the line

map.resources :ingredients

in your routes.rb file? If so, remove it -- it's supposed to be replaced by the nested route.

Noel
Reply By: zuufuzu Reply Date: 4/17/2008 12:26:36 PM
Hello Noel,

that's it! (wild guess?) Thank you, now I think this routes stuff becomes clearer.

Now i will go on with the rest of the chapter.

Until my next problem - i hope not -.

zufuzu

quote:
Originally posted by noelrap

Okay, here's a wild guess -- do you still have the line

map.resources :ingredients

in your routes.rb file? If so, remove it -- it's supposed to be replaced by the nested route.

Noel




Go to topic 70687

Return to index page 1