to be honest, I almost find html forms more straightforward than Rails form helpers. I’m trying to turn this text form into a select box with options Canada, United States, Mexico as strings
<p><%= f.label :country %><br />
<%= f.text_field :country %></p>
Because the model is already represented in the block variable “f”, I’m not sure how to alter the syntax because the model is usually represented first in the complicated hash of variables and options http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
Can anyone show me?
The following should work:
You can read more in the Rails Guides & API docs. As @ka8751 says, though, if you have a
Countrymodel,collection_selectmakes this far easier:where
:idis used for the actualvalueof the<option>tag and:nameis used for what is displayed.If you don’t have a
Countrymodel, you should consider one for the sake of database normalization.