How to set up form for a hash in Rails?

前端 未结 3 576
悲哀的现实
悲哀的现实 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:18

    Based on this article you should change the name in text_field_tag to

    <% @hash.keys.each do |key| %>
      
    <%= f.label key %>
    <%= text_field_tag "hash[" + key + "]", @hash[key] %>
    <% end %>

提交回复
热议问题