【发布时间】:2016-03-14 05:28:00
【问题描述】:
我正在使用form_for 创建新的Records。每条记录都有一个主照片 url :photo 和三个可选的照片 url,我将它们存储在一个序列化数组中,other_photos。
在我的表单中,我希望用户可以选择添加最多三个额外的照片网址,这些网址将存储在 other_photos[0]、other_photos[1] 和 other_photos[2] 中
我将列添加到数据库中,将serialize :other_photos, Array 添加到模型中,并允许强参数:other_photos => []
如何在我的表单中处理这个问题?现在,我将这张照片作为我的主要照片:
<%= form_for @record do |r| %>
...
<%= label_tag :name, "IMAGE URL:", class: "login-label" %>
<%= r.text_field :photo, size: 50 %>
如何设置other_photos 的参数?这不起作用:
<%= r.text_field :other_photos[0], size: 50 %>
【问题讨论】:
标签: ruby-on-rails arrays forms serialization