【发布时间】:2018-03-16 18:23:10
【问题描述】:
我使用 cocoon gem 创建了一个带有嵌套属性的表单。单击 link_to_add_association 时,它将附加标签和 text_field。但是,我希望标签名称是动态的,因为每个标签的标签名称都会不同。例如,我想将“A:”作为第一个标签的标签名称,将“B:”作为第二个标签的标签名称,依此类推。有没有可能做到这一点?
/_mcq.html.erb
<%= f.fields_for :mcq_options do |option| %>
<%= render 'question_paper_generations/mcq_option_fields', f: option %>
<% end %>
<div><%= link_to_add_association 'Add Option', f, :mcq_options %></div>
/_mcq_options_fields.html.erb
<%= f.label :option %>
<%= f.text_field :option, class: 'form-control' %>
【问题讨论】: