Ruby on rails Rails 5 ActiveRecord更新表单中的序列化数组
我有一个字段是序列化数组。它被加载到我的模型中,并以以下形式访问:Ruby on rails Rails 5 ActiveRecord更新表单中的序列化数组,ruby-on-rails,arrays,forms,activerecord,Ruby On Rails,Arrays,Forms,Activerecord,我有一个字段是序列化数组。它被加载到我的模型中,并以以下形式访问: class Site < ApplicationRecord serialize :steps, Array end <table class="listing" summary="Site list"> <tr class="header"> <th>Name</th> <th>Step 1</th>
class Site < ApplicationRecord
serialize :steps, Array
end
<table class="listing" summary="Site list">
<tr class="header">
<th>Name</th>
<th>Step 1</th>
<th>Step 2</th>
<th>Step 3</th>
<th>Actions</th>
</tr>
<% @sites.each do |site| %>
<tr>
<td><%= site.name %></td>
<% site.steps.each do |step| %>
<td><%= step %></td>
<% end %>
<td class="actions">
<%= link_to("Show", site_path(site), :class => 'action show') %>
<%= link_to("Edit", edit_site_path(site), :class => 'action edit') %>
<%= link_to("Delete", delete_site_path(site), :class => 'action delete') %>
</td>
</tr>
<% end %>
</table>
因此,步骤将作为数组中的最后一个条目提交如何正确显示表单并将更新后的数组返回控制器进行处理?您的
文本\u字段需要多个
设置为真
。我相信在你的情况下,像这样的事情应该行得通
<%= f.text_field(:steps, { multiple: true, value: @site.steps[step] }) %>
Attribute was supposed to be a Array, but was a String.
<%= f.text_field(:steps, { multiple: true, value: @site.steps[step] }) %>