我有一个
nested
类型
New
这种方法效果很好。但在我的
edit
表单嵌套输入为空。这是我的表格:
<%= simple_form_for @company , url: admin_company_path(@company) do |f| %>
<%= f.simple_fields_for :licence do |p| %>
<%= p.input_field :number %>
<% end %>
<% end %>
我的公司模式:
accepts_nested_attributes_for :licence
has_one :licence , inverse_of: :company , :dependent => :destroy
我的许可证型号:
belongs_to :company
我在控制器中的编辑方法:
def edit
// i get company id with before_action
@company.build_licence
end
我在控制器中的新方法:
def new
@company = Company.new
@company.build_licence
end
新建/创建方法非常适合此代码。但编辑表单不会填充嵌套的模型输入。