Finding a specific category

For the following controller:

[email protected] ~/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
[email protected] ~/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

On 12 Feb 2008, at 10:13, Thufir wrote:

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

On Tue, 12 Feb 2008 10:48:11 +0000, Frederick C. 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?

[email protected] ~/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
[email protected] ~/oreilly-recipes-categories $ cat app/models/recipe.rb
class Recipe < ActiveRecord::Base
belongs_to :category
end
[email protected] ~/oreilly-recipes-categories $

thanks,

Thufir

On 12 Feb 2008, at 20:09, Thufir wrote:

On Tue, 12 Feb 2008 10:48:11 +0000, Frederick C. 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