ruby - How to get each element of a Rails list into select_tag in a form? -
i have rails list :
["ananda college", "nalanda college"]
it taken database. have selected 1 column , taken entries. need put list select tag! select each 1 select box. how can this?
i tried add each block inside select_tag , didn't work.
ps : list dynamically generated
you need use form helper options_for_select
takes array.
a common way of doing setting array in controller:
@colleges = college.uniq.pluck(:name)
then in view:
<%= f.select :college, options_for_select(@college) %>
take @ docs options_for_select more implementation details.
Comments
Post a Comment