【发布时间】:2016-04-15 00:56:38
【问题描述】:
我有一个“食谱”,其中有_many“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>
【问题讨论】:
-
您的 POST 参数是什么样的,以及为成分选择标签生成的 html 是什么?它们是否符合预期?
标签: ruby-on-rails mongoid strong-parameters