I am using the following to allow my users to select their sex in their profile.
<%= f.select (:sex, %w{ Male Female }) %>
How would I create a blank value that the list would default to if nothing has been passed to the user.sex column? I am simply passing male or female as a string.
The purpose is I want a blank value so a validation can make sure they are aware they have to select it.
There are two possibilities, depending on what you're after:
include_blank
<%= f.select (:sex, %w{ Male Female }, :include_blank => true) %>
This will always include a blank option in the select, which will allow people to set the value back to the blank value if they're seeing this on an edit form.
prompt
<%= f.select (:sex, %w{ Male Female }, :prompt => "Gender...") %>
This will include the specified prompt value, so long as the field hasn't already been set. If it has (on an edit form for example), there's no need to remind the user that they need to select a value so the prompt doesn't appear
I think you can do something like this:
<%= f.select (:sex, %w{ Male Female }, {:include_blank => 'None Specified'} ) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With