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
On 6 Nov 2007, at 19:00, Martin E. 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
Frederick C. wrote:
On 6 Nov 2007, at 19:00, Martin E. 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
@[email protected]
but still get error
“undefined method `ingredients’”
I’m using rails 1.2.5 does that make a difference
Martin
Frederick C. wrote:
On 6 Nov 2007, at 19:46, Martin E. wrote:
Fred
tried that
@[email protected]
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
On 6 Nov 2007, at 19:46, Martin E. wrote:
Fred
tried that
@[email protected]
just spotted the other problem: @recipe isn’t a single @recipe as I
expected, but an array of recipes.
Fred
On 6 Nov 2007, at 21:26, Martin E. 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.
Frederick C. wrote:
On 6 Nov 2007, at 21:26, Martin E. 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