i have a database Country filled with (obvious) contries. now i would like to display them in the select_tag in my view (like a drop down list).
i tried puttin in options_for_select sth like @show_me_the_countries_mama.each do |f| (‘[‘ + f.printable_name + ‘]’ + ‘,’). this would list countries each one of them in [] brackets and with spaces in normal view. but it doesnt work in options_for_select for doing the drop down list.
i have:
‘get’ do %>
Country:
how can i solve this? i somehow have to put an array of countries in options_for_select and now i am asking how should i do this. shoud i write separate method in the model for getting the proper array of countries and then inserting them here or..?
thank you for your answers
Try to use the
collection_selecttag:Where :id and :printable_name are the methods passed to each model in Country.all to get the value and display parts of a select option, respectively.
You could also look at formtastic for very easy form generation.