У меня есть «Рецепт», который имеет_много «Ilists» и «Ilist» имеет_one «ингредиент», я пытаюсь представить все в одной форме, но у меня проблема с сильными параметрами. Я могу отправить форму, но, глядя на консоль, я вижу в запросе POST:
"Unpermitted parameter: ingredient_attributes"
recipes_controller.rb
class RecipesController < ApplicationController
before_action :set_recipe, only: [:show, :edit, :update, :destroy]
def index
@recipes = Recipe.all
end
def create
@recipe = Recipe.new
6.times { @recipe.ilists.build }
end
.
.
private
def recipe_params
params.require(:recipe).permit(:title, :photo, ... , :description, :calories, ilists_attributes: [ :ingredient_attributes, :quantity])
end
end
Пробовал писать так, но не работает:
, ilists_attributes: [ ingredient_attributes: [ name, calories, ... ], :quantity])
Пожалуйста, помогите, это убивает меня!
это форма, с которой я отправляю
<%= f.fields_for :ilists do |builder| %>
<tr>
<%= builder.fields_for :ingredient, Ingredient.new do |b| %>
<td><%= b.collection_select(:_id, Ingredient.all, :id, :name) %></td>
<% end %>
<td><%= builder.text_field :quantity %></td>
</tr>