【发布时间】:2015-06-09 22:46:17
【问题描述】:
我有一个表单,它正在向具有嵌套属性的模型提交数据。我正在使用 select 从选项列表中进行选择。
Articles 模型为 Documents 模型接受_nested_attributes_,该模型具有称为 Attachment 的_attached_file。附件的 url_path 是选择字段应该选择的内容。
如何更改选择字段的值?
HTML 现在看起来像这样:
<select id="article_document" name="article[document]">
<option>...</option>
</select>
但我想要这个:
<select id="article_document_url_path" name="article[document][url_path]">
<option>...</option>
</select>
Ruby 看起来像这样:
<%= form_for @article, :html => { :multipart => true } do |f| %>
<%= f.select( :document,
options_for_select(@article.attachment_list.map{ |c| [c, {'data-img-src' => c }] }) ) %>
<% end %>
Rails 4.1.8,红宝石 2.1.5p273
【问题讨论】:
标签: html ruby-on-rails ruby ruby-on-rails-4