I am implementing a view on one model with three tables; one of those tables is included in this table Are:
Recipe:
class recipe & lt; ActiveRecord :: Base # Valid: Name ,: Attendance = & gt; Correct # Confirmation: Instructions ,: Attendance = & gt; True # has_and_belongs_to_many: ingradients has_many: ingredients_recipes has_many: content, via => : Ingredients_recipes accepts_nested_attributes_for: ingredients_recipes ,: allow_destroy = & gt; True End
Component:
Class Component & lt; ActiveRecord :: Base # has_and_belongs_to_many: Recipes have_many: ingredients_recipes has_many: recipes ,: through = & gt; : Ingredients_recipes end
and the joining table between them:
class content reciprocity & lt; ActiveRecord :: Base is_to: Recipes belong_to: Content,: foreign_key = & gt; "Ingredient_id" Representative: Name ,: to = & gt; : End of content
This works fine when I create a new recipe - I can edit the recipe lines and everything runs smoothly. When I create a view to show the recipe with the component name from the content table, I created a representative in the host table. But when I try to use within the representative view:
& lt;% @ recipe.ingredients_recipes.each do | R | & Gt%; & Lt;% = r.ingredient_id% & gt; & Lt; Br> & Lt;% = r.name% & gt; & Lt;% end% & gt;
I get the following error:
uninitialized continuous content Recipe :: Content
When I & lt; % = R.name%> Runs without errors without errors Whether I am defining a representative incorrectly or what could be the reason for this?
I believe your respective associations should be singular, not plural in related areas. , Ex:
class content reciprocity & lt; ActiveRecord :: Base is_to: recipe is_to: component,: foreign_key = & gt; "Ingredient_id" Representative: Name ,: to = & gt; : Component End
Also, check the case of your class name. It should either be all singular (ingredient resolutions) or all plural (material rhesis) ... I'm not sure that, but I know that it should not be mixed.
Finally, do you join the model? If you do not have any other feature in content ribs, then just use your commented lines like HABTM.
Comments
Post a Comment