【发布时间】:2016-04-19 08:20:00
【问题描述】:
我使用嵌套表单为多个数据输入添加一行表单。 但是,使用 link_to 生成的表单上的所有样式都会丢失。 查看生成的代码,所有样式都在那里,但是当我添加字段时,它不会呈现样式。 我尝试了同时呈现为表格行和 div 行(引导程序)的部分。最初生成的行看起来很完美,但添加的行都被弄乱了,并且没有与任何东西对齐。 谢谢!
在 application_helper 中
def link_to_add_fields(name, f, association, readonly)
new_object = f.object.send(association).klass.new
id=new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |builder|
render("my partial form", f: builder, readonly: readonly)
end
link_to(name, "#", class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
在我的 new.html 中
<table class="table table-bordered">
<thead>
<tr>
<th>Customer</th>
<th>Description</th>
<th>Notes</th>
<th></th>
</tr>
</thead>
<tbody>
<%= f.fields_for :my_association do |builder| %>
<%= render "my_partial", f: builder%>
<% end %>
false%>
在我的部分中
<tr>
<td><%= f.collection_select(:customer_id, @customers, :id, :fullname, :include_blank=>'Select') %>
<%= f.hidden_field(:id)%></td>
<td> <%= f.text_field(:description) %></div>
<td> <%= f.text_area(:note, :size=> "25x1") %></td>
<td> <%= f.hidden_field :_destroy %><%= link_to "remove", "#", class: "remove_fields"%> </td>
</tr>
【问题讨论】:
标签: css ruby-on-rails forms twitter-bootstrap nested