Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.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 如何让两个循环在彼此之间显示信息_Ruby On Rails_Ruby_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 如何让两个循环在彼此之间显示信息

Ruby on rails 如何让两个循环在彼此之间显示信息,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我有两个输入字段,由两个不同的哈希生成 table_head = {"key1"=>"thead1", "key2"=>"thead2", "key3"=>"thead3", "key4"=>"thead4"} table_content = {"1"=>"column1", "2"=>"column2", "3"=>"column3", "4"=>"column4"} <%= form_for([@category, @page],

我有两个输入字段,由两个不同的哈希生成

table_head = {"key1"=>"thead1", "key2"=>"thead2", "key3"=>"thead3", "key4"=>"thead4"}

table_content = {"1"=>"column1", "2"=>"column2", "3"=>"column3", "4"=>"column4"}

 <%= form_for([@category, @page], url: update_pages_path) do |f| %>

    <% @page.table_head.each_with_index do |(key, value), i| %>
      <%= text_field_tag ('header[' + i.to_s + ']'), value %> 
    <% end%>


    <% @page.table_content.each_with_index do |(key, value), i| %>
      <%= select_tag 'content[' + i.to_s + ']', options_for_select(@category_keys, value), { :multiple => true, :size => 3}  %>
    <% end%>


 <% end %>
但是在内容字段中不能输入select
的默认
选项

如何将字段排序为head、content、head、content等。。插入头、头、头、头、内容、内容等。

表头={“键1”=>“thead1”、“键2”=>“thead2”、“键3”=>“thead3”、“键4”=>“thead4”}
table_head = {"key1"=>"thead1", "key2"=>"thead2", "key3"=>"thead3", "key4"=>"thead4"}

table_content = {"1"=>"column1", "2"=>"column2", "3"=>"column3", "4"=>"column4"}

<%= form_for([@category, @page], url: update_pages_path) do |f| %>
  <% @page.table_head.zip(@page.table_content).each do |head, content| %>
    <% head_key, head_value = head %>
    <% content_key, content_value = content %>
    <%= text_field_tag ('header[' + head_key + ']'), head_value %> 
    <%= select_tag 'content[' + content_key + ']', options_for_select(@category_keys, content_value), { :multiple => true, :size => 3}  %>
  <%end%>
<% end %>
表内容={“1”=>“column1”,“2”=>“column2”,“3”=>“column3”,“4”=>“column4”} 正确,:大小=>3}%>
我将如何将其应用于表单?像这样@user3234020将更加具体,并询问我如何使用
.zip
单独访问每个哈希值,而不是作为一个完整的哈希值。我试试你最新的答案。
table_head = {"key1"=>"thead1", "key2"=>"thead2", "key3"=>"thead3", "key4"=>"thead4"}

table_content = {"1"=>"column1", "2"=>"column2", "3"=>"column3", "4"=>"column4"}

<%= form_for([@category, @page], url: update_pages_path) do |f| %>
  <% @page.table_head.zip(@page.table_content).each do |head, content| %>
    <% head_key, head_value = head %>
    <% content_key, content_value = content %>
    <%= text_field_tag ('header[' + head_key + ']'), head_value %> 
    <%= select_tag 'content[' + content_key + ']', options_for_select(@category_keys, content_value), { :multiple => true, :size => 3}  %>
  <%end%>
<% end %>