Colin Law wrote: > 2009/6/17 Hugues Brunelle <[email protected]>: >> >> Thank you Colin, it seems to work since "#" character appear for each >> ingredient of a product. Now I must figure out how I get the >> ingredient's name. Can you give me an exemple, since >> product.ingredients.name doesn't work? > > product.ingredients is an array, you could reference > product.ingredients[0].name or you could iterate the array using > product.ingredients.each. Another useful construct is > product.ingredients.map(&:name) which will give you an array of > ingredient names. > In all of this don't forget to watch out for a product with no > ingredients (product.ingredients is nil in this case) which can give > you run-time errors if you have not caught them. The same applies to > stack.products. > > I wonder whether it would be useful for you to run through some basic > Ruby tutorials to get a bit more grounding on the basics of Ruby. > > Good Luck > > Colin
Thank you Colin. I managed to get it right with your advice using product.ingredients.each do |ingredient| and then using ingredient.name I will do some Arrays and Hashes tutorials right away since I think I'm gonna need to manipulate data that way sooner or later. -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

