rails 4 populate dropdown values from database -


i have dropdown in rails form:

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

this works fine how can make dynamic. (interacting model data)

i have controller action containing @list = list.all

how can populate id , name in combobox. i've been searching around, unclear it. can help>

you can use options_from_collection_for_select.

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

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -