ROR:值数组的隐藏形式

时间:2015-05-08 12:38:49

标签: ruby-on-rails ruby

我有一个名为schema的典型ruby哈希:

{ 
  "car"=>{"col"=>["blue","red"], "engine"=>["HHd4M","Rafa"]},
  "train"=>{"col"=>"black","green"], "engine"=>["8495f","mad"]}
}

我想为此哈希创建一个隐藏的表单。

<%=form_tag send_form_database_querys_path, method: :get do %>
    <% schema.each do |vehicle,opt| 
            opt.each do |key,vals| #key = col or key = engine, vals = array
                vals.each do |val| #val = each element in an array
            %>
            <%= hidden_field_tag "schema[#{vehicle}][#{key}][]", val  %>
    <% end end end %>

        <%= button_tag :class => "btn btn-warning", :name => 'delete' do %> <%= t "arraydb_delete_selected" %> <% end %>    
    <% end %>

不知怎的,如果我提交它,它告诉我“错误请求” 我的隐藏表格有什么问题?

2 个答案:

答案 0 :(得分:0)

尝试将表单方法更改为post

<%=form_tag send_form_database_querys_path, method: :post do %>

也许有帮助。

答案 1 :(得分:0)

[之后,你的哈希中缺少"train"=>{"col"=>。它应该是

{ 
  "car"=>{"col"=>["blue","red"], "engine"=>["HHd4M","Rafa"]},
  "train"=>{"col"=>["black","green"], "engine"=>["8495f","mad"]}
}