ruby on rails - How can I have 2 loops display information in-between each other -
i have 2 input fields generated 2 different hashes.
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) |f| %> <% @page.table_head.each_with_index |(key, value), i| %> <%= text_field_tag ('header[' + i.to_s + ']'), value %> <% end%> <% @page.table_content.each_with_index |(key, value), i| %> <%= select_tag 'content[' + i.to_s + ']', options_for_select(@category_keys, value), { :multiple => true, :size => 3} %> <% end%> <% end %>
this makes 4 table_head
inputs , 4 table_content
selects. need them ordered, table head input, table content select, table head input, content select , on. not table head inputs , table content selects.
i fields
<% @page.table_head.each_with_index |(key, value), i| %> <%= text_field_tag ('header[' + i.to_s + ']'), value %> <%= select_tag 'content[' + i.to_s + ']', options_for_select(@category_keys), { :multiple => true, :size => 3} %> <% end%>
but default options_for_select
value
cant put in content field.
how can have fields ordered head, content, head, content etc.. insead of head, head, head, head, content, content etc..
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) |f| %> <% @page.table_head.zip(@page.table_content).each |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 %>
Comments
Post a Comment