How to set up form for a hash in Rails?

前端 未结 3 630
悲哀的现实
悲哀的现实 2021-02-06 01:47

I have some data associated with a model that is in a hash. The hash is generated in the controller: @hash.

What is the proper way to create a form for this

3条回答
  •  眼角桃花
    2021-02-06 02:12

    When you use the helpers that end with _tag that's what happens.

    Instead of text_field_tag ... use f.text_field ....

    In order to get a hash like params => {:hash => {:field1 => "", :field2 => ""}} you have to pair up form_for with f.input_field_type instead of simply input_field_tag.

    See the difference?

提交回复
热议问题