【发布时间】:2018-08-17 11:50:23
【问题描述】:
我有一个模型配方和一个模型成分。配方 has_many :ingredients 和成分 belongs_to :recipe。 我正在使用 Cocoon 和 Simple Forms 创建嵌套表单。 主窗体正在工作和显示,但由于某种原因嵌套窗体没有呈现。 知道为什么吗?
模型
class Recipe < ApplicationRecord
has_many :ingredients
end
class Ingredient < ApplicationRecord
belongs_to :recipe
end
配方控制器(参数)
def recipe_params
params.require(:recipe).permit(:title, :description, :image,
ingredients_attributes: [:id, :name, :_destroy],
directions_attributes: [:id, :step, :_destroy])
end
查看
<%= simple_form_for @recipe do |f| %>
<div class="field">
<h3>Recipe</h3>
<%= f.input :title %>
<%= f.input :description %>
<%= f.input :image, as: :file %>
<div id="ingredients">
<h3>Ingredients</h3>
<%= f.simple_fields_for :ingredients do |ingredient| %>
<p>ajsd</p>
<%= render 'ingredients_fields', f: ingredient %>
<%= link_to_add_associtation 'Add Ingredient', f, :ingredients %>
<% end %>
</div>
<%= f.button :submit, class: "button button-highlight button-block" %>
</div>
<% end %>
div#ingredients 中的 simple_forms 未呈现。
【问题讨论】:
标签: ruby-on-rails model-view-controller simple-form nested-forms cocoon-gem