Hi all
I’m quite new to Rails an am managing an application, and I want to add
a “Not Selected” option to a dropdown-list.
As it stands now, once you’ve chosen an option in the dropdownlist the
value is stored in the database, and then it’s impossible to remove the
option unless you choose another option (Radiobutton-style). If no
option is selected, null is stored as that dropdown-lists value.
Therefor I need an “Not Selected”-option, that when selected would save
the value null in the database.
There must’ve been plenty of cases where something similar to this has
been implemented before, yet I have failed to find any resources despite
searching for a good couple of hours.
This is how the form looks right now:
<%= account_pref.input “editorial_#{key}”.to_sym, :as => :radio,
:collection => options_for(Editorial, key.to_sym), :wrapper_html => {
:class => “compact” }, :label => key.titleize %>
What I was thinking was that maybe there’s some method similar to the
option_for one , so that I could add a “Not Stated” option to the
collection, and then somehow link its value to null.
If anyone can either give me some direct tips for solutions, or a place
to find a good resource on this, I’d be very happy.
Regards,
Emil