For the following controller: thufir@arrakis ~/oreilly-recipes-categories $ cat app/controllers/ recipes_controller.rb -n | head -n 18 | tail -n 3 16 @recipe = Recipe.find(params[:id]) 17 @categories= Category.find_all 18 end thufir@arrakis ~/oreilly-recipes-categories $ http://oreilly-recipes-categories.googlecode.com/svn/trunk/app/ controllers/recipes_controller.rb I just want to pull up the Category instance which belongs to this Recipe instance. What should be on line 17 for that, please? thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ 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 12 Feb 2008, at 10:13, Thufir wrote:> > For the following controller: > > thufir@arrakis ~/oreilly-recipes-categories $ cat app/controllers/ > recipes_controller.rb -n | head -n 18 | tail -n 3 > 16 @recipe = Recipe.find(params[:id]) > 17 @categories= Category.find_all > 18 end > thufir@arrakis ~/oreilly-recipes-categories $ > > http://oreilly-recipes-categories.googlecode.com/svn/trunk/app/ > controllers/recipes_controller.rb > > I just want to pull up the Category instance which belongs to this > Recipe > instance. What should be on line 17 for that, please?@recipe.categories or @recipe.category depending on whether it''s a belongs_to or a has_many. Fred> > > thanks, > > Thufir > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Tue, 12 Feb 2008 10:48:11 +0000, Frederick Cheung wrote:> @recipe.categories or @recipe.category depending on whether it''s a > belongs_to or a has_many.And then in the view (show), basically, the @category instance can be used just as the @recipe instance is used? thufir@arrakis ~/oreilly-recipes-categories $ cat app/controllers/ recipes_controller.rb -n | head -n 18 | tail -n 4 15 def show 16 @recipe = Recipe.find(params[:id]) 17 @category = @recipe.category 18 end thufir@arrakis ~/oreilly-recipes-categories $ cat app/models/recipe.rb class Recipe < ActiveRecord::Base belongs_to :category end thufir@arrakis ~/oreilly-recipes-categories $ thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ 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 12 Feb 2008, at 20:09, Thufir wrote:> > On Tue, 12 Feb 2008 10:48:11 +0000, Frederick Cheung wrote: > >> @recipe.categories or @recipe.category depending on whether it''s a >> belongs_to or a has_many. > > And then in the view (show), basically, the @category instance can be > used just as the @recipe instance is used? >of course. Fred> > thufir@arrakis ~/oreilly-recipes-categories $ cat app/controllers/ > recipes_controller.rb -n | head -n 18 | tail -n 4 > 15 def show > 16 @recipe = Recipe.find(params[:id]) > 17 @category = @recipe.category > 18 end > thufir@arrakis ~/oreilly-recipes-categories $ cat app/models/recipe.rb > class Recipe < ActiveRecord::Base > belongs_to :category > end > thufir@arrakis ~/oreilly-recipes-categories $ > > > thanks, > > Thufir > > > --~--~---------~--~----~------------~-------~--~----~ > 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 > -~----------~----~----~----~------~----~------~--~--- >