Form_tag parameters in nested hash

前端 未结 1 1458
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 13:49

I have a form that doesn\'t have a model associated with it, so I\'m using form_tag rather than form_for. As expected, when the user submits the form

1条回答
  •  深忆病人
    2021-01-30 14:36

    You can use fields_for inside a form_tag for a more formal way of expressing a namespace.

    fields_for :form_fields do |ff|
      ff.text_field :my_text_field
      ff.select :my_select_tag
    end
    

    Alternatively just namespace all your form inputs, as such:

    text_field_tag "form_fields[my_text_field]"
    select_tag "form_fields[my_select_tag]" ...
    

    etc. Then you will get params[:form_fields] = {:my_text_field => "foo", :my_select_tag => "bar"}, which I think is what you wanted.

    0 讨论(0)
提交回复
热议问题