rails 4 populate dropdown values from database

后端 未结 3 721
清酒与你
清酒与你 2021-02-06 01:26

I have a dropdown in a rails form:

<%= f.select :lists, [[\"test1\", 1], [\"test2\", 0]] %>

This works fine but how can I make it dynamic

3条回答
  •  无人共我
    2021-02-06 01:49

    You can use options_from_collection_for_select.

    <% options = options_from_collection_for_select(@list, 'id', 'name') %>
    <%= f.select :all_val,  options %>
    

提交回复
热议问题