更新时间:1970-01-01 07:59:12
Rails 可以序列化集合,这应该会更容易.
Rails can serialize collections, which should make this easier.
如果您在视图中像这样将输入命名为字段[]":
If you name your inputs like 'field[]' like this in your view:
<% @ages.each do |age| %>
<%= text_field_tag 'ages[]', age %>
<% end %>
然后您可以在提交时访问控制器中的所有年龄":
Then you can access all 'ages' in your controller on submission:
@ages = params[:ages] # ['1', '3', '7']