当我尝试在下面的视图代码中使用fields_for时,company_name未显示在视图中。我做错了什么?
= form_for @company do |f|
-if @company.errors.any?
#error_explanation
%h2= "#{pluralize(@company.errors.count, "error")} prohibited this company from being saved:"
%ul
- @company.errors.full_messages.each do |msg|
%li= msg
=f.fields_for :showing do |t|
.field
= t.label :company_name
= t.text_field :company_name
.field
= f.label :geography
= f.text_area :geography
答案 0 :(得分:2)
您是否在控制器中构建showing
对象?
@company.build_showing
如果您在accepts_nested_attributes_for
模型上定义了Company
,那么您需要在控制器和父对象中设置嵌套对象。