【发布时间】:2015-03-07 16:25:27
【问题描述】:
我在我的 rails 4.1 + activeadmin 应用程序中使用 cocoon gem (1.2.6)。 link_to_add_association 在 ERB 表单中添加了带有 new 的空字段。请参考下面的输入ID
<input id="lease_information_lease_units_attributes_new_lease_units_property_name" type="text" name="lease_information[lease_units_attributes][new_lease_units][property_name]">
当我点击 link_to_add_association 时会创建带有 id 的字段。
<input id="lease_information_lease_units_attributes_1420800589434_property_name" type="text" name="lease_information[lease_units_attributes][1420800589434][property_name]">
我的lease_informations/_lease_units.html.erb 表格:
<%= javascript_include_tag :cocoon %>
<div id='lease_units'>
<%= f.semantic_fields_for :lease_units do |lease_unit| %>
<%= render 'lease_unit_fields', f: lease_unit %>
<% end %>
<div class='links'>
<%= link_to_add_association image_tag("icon-new.png", height: '18', width: '18'), f, :lease_units, title: "Add Unit" %>
</div>
</div>
部分_lease_unit_fields.html.erb:
<div class='nested-fields'>
<table>
<tbody>
<tr >
<td class="col col-unit_type">
<%= f.text_field :unit_type %>
</td>
<td class="col col-unit">
<%= f.text_field :unit %>
</td>
<td class="col col-action">
<%= link_to_remove_association image_tag("icon-remove.png", height: '18', width: '18'), f, title: "Remove Unit" %>
</td>
</tr>
</tbody>
</table>
</div>
我的管理员/lease_information.rb
ActiveAdmin.register LeaseInformation do
menu false
controller do
def new
@page_title="Data Entry Form"
@lease_information = LeaseInformation.new
# @lease_information.lease_units.build
end
end
form do |f|
tabs do
tab 'Units' do
table_for resource.lease_units do
column :unit_type
column :unit
end
render "lease_units", f: f # rendering the partial here
end
f.actions do
f.action :submit, label: "Submit"
f.cancel_link(admin_jobs_path)
end
end
end
因此,嵌套字段没有保存在数据库中。谁能帮我解决这个问题?
【问题讨论】:
-
能否请您张贴您要添加lease_units partial的主要表格
-
在帖子中添加了主表单。请参考
-
请在
admin/lease_information.rb文件中移动以下行,我认为这将解决您的问题。 `` @ManiDavid 你得到解决方案了吗?
标签: activeadmin ruby-on-rails-4.1 cocoon-gem