У меня есть три модели: ингридиент, recipe_ingredient и recey
class Ingredient < ApplicationRecord
has_many :recipe_ingredients
end
class RecipeIngredient < ApplicationRecord
belongs_to :recipy, :dependent => :destroy
belongs_to :ingredient
end
class Recipy < ApplicationRecord
has_many :recipy_steps
has_many :recipe_ingredients, :dependent => :delete_all
end
Я пытаюсь получить доступ к атрибуту ing_name в таблице ингредиентов со страницы показа получателей.
<% @recipe_ingredients.each do |ing| %>
<p> <%= ing.amount %> <%= ing.unit %>
<%= ing.ingredient.ing_name %>
</p>
def Showиз контроллера получателей:
def show
@recipe_ingredients = @recipy.recipe_ingredients
end
Но я получаю следующее сообщение об ошибке: неопределенный метод `ing_name 'для nil: NilClass
Мои ингредиенты:
def ingredient_params
params.require(:ingredient).permit(:ing_name)
end
Кажется, это работает так:
<%= Ingredient.where(id: ing.ingredient_id).pluck(:ing_name) %>
Но это не использует связь между таблицами, если я правильно понимаю?Любая помощь?Благодаря.