Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 5 ActiveRecord更新表单中的序列化数组_Ruby On Rails_Arrays_Forms_Activerecord - Fatal编程技术网

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] }) %>