My models are class BakeryOutput < ActiveRecord::Base belongs_to :recipe belongs_to :customer end class Recipe < ActiveRecord::Base has_many :ingredient_recipes has_many :ingredients, :through => :ingredient_recipes has_many :bakery_outputs validates_presence_of :name validates_uniqueness_of :name end class IngredientRecipe < ActiveRecord::Base belongs_to :ingredient belongs_to :recipe end class Ingredient < ActiveRecord::Base has_many :ingredient_recipes has_many :recipes, :through => :ingredient_recipes validates_presence_of :name validates_uniqueness_of :name end and in my controller for the show method def show @bakery_output = BakeryOutput.find(params[:id], :include => [:recipe, :customer]) @recipe = Recipe.find(:all, :conditions => ["id = ?", @bakery_output.recipe_id]) @ingredients=Recipe.ingredients respond_to do |format| format.html # show.rhtml format.xml { render :xml => @ingredients.to_xml } end end In the controller the first two statement work ok but the third @ingredients=Recipe.ingredients generates an error "undefined method `ingredients'' for Recipe:Class" I''m trying to collect all the ingredients in a recipe Can someone tell me where I am going wrong, this is my first app. regards Martin -- 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 -~----------~----~----~----~------~----~------~--~---
On 6 Nov 2007, at 19:00, Martin Evans wrote:> In the controller the first two statement work ok but the third > @ingredients=Recipe.ingredients > generates an error > > "undefined method `ingredients'' for Recipe:Class" >It should be @recipe.ingredients Fred> I''m trying to collect all the ingredients in a recipe > > Can someone tell me where I am going wrong, this is my first app. > > regards > Martin > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 6 Nov 2007, at 19:00, Martin Evans wrote: >> In the controller the first two statement work ok but the third >> @ingredients=Recipe.ingredients >> generates an error >> >> "undefined method `ingredients'' for Recipe:Class" >> > It should be @recipe.ingredients > > Fredtried that @ingredients=@recipe.ingredients but still get error "undefined method `ingredients''" I''m using rails 1.2.5 does that make a difference Martin -- 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 -~----------~----~----~----~------~----~------~--~---
On 6 Nov 2007, at 19:46, Martin Evans wrote:> > Frederick Cheung wrote: >> On 6 Nov 2007, at 19:00, Martin Evans wrote: >>> In the controller the first two statement work ok but the third >>> @ingredients=Recipe.ingredients >>> generates an error >>> >>> "undefined method `ingredients'' for Recipe:Class" >>> >> It should be @recipe.ingredients >> >> Fred > > tried that > @ingredients=@recipe.ingredientsjust spotted the other problem: @recipe isn''t a single @recipe as I expected, but an array of recipes. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 6 Nov 2007, at 19:46, Martin Evans wrote: > >>> >>> Fred >> >> tried that >> @ingredients=@recipe.ingredients > > just spotted the other problem: @recipe isn''t a single @recipe as I > expected, but an array of recipes. > > FredSo how do I need to write it please -- 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 -~----------~----~----~----~------~----~------~--~---
On 6 Nov 2007, at 21:26, Martin Evans wrote:> > Frederick Cheung wrote: >> On 6 Nov 2007, at 19:46, Martin Evans wrote: >> >>>> >>>> Fred >>> >>> tried that >>> @ingredients=@recipe.ingredients >> >> just spotted the other problem: @recipe isn''t a single @recipe as I >> expected, but an array of recipes. >> >> Fred > > So how do I need to write it please@bakery_output = BakeryOutput.find(params[:id], :include => [:recipe, :customer]) @recipe = Recipe.find(:all, :conditions => ["id = ?", @bakery_output.recipe_id]) should be @recipe = @bakery_output.recipe. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 6 Nov 2007, at 21:26, Martin Evans wrote: > >>> just spotted the other problem: @recipe isn''t a single @recipe as I >>> expected, but an array of recipes. >>> >>> Fred >> >> So how do I need to write it please > > @bakery_output = BakeryOutput.find(params[:id], :include => > [:recipe, :customer]) > @recipe = Recipe.find(:all, :conditions => ["id = ?", > @bakery_output.recipe_id]) > > should be @recipe = @bakery_output.recipe.Thanks a lot, thats fixed it I''ve been struggling with that for quite a while regards Martin -- 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 -~----------~----~----~----~------~----~------~--~---