我有一个数组[["Company Name", "Field6"], ["Email", "Field5"]]
从该数组中,我正在创建具有值的字段数组:
[
[{:label=>"Company Name", :value=>"gfdgfd"}],
[{:label=>"Email", :value=>"gfdgfd@gfd.pl"}]
]
使用
fields = [["Company Name", "Field6"], ["Email", "Field5"]]
# first element in array is Label and second is param id
fields_with_values = fields.collect do |field|
[
label: field[0],
value: params[field[1]]
]
end
然后我想将该标签和值传递给 erb 模板(类似):
# template.erb
<% fields_with_values.each do |field| %>
l: <%= field.label %>
v: <%= field.value %>
<% end %>
收集这些 fields_with_values 的最佳方式是什么?也许我应该使用 Object.new