Reputation: 1
I have a use case in a web page, in which I need to have "nil" value also, besides true and false. I have implemented it like bellow but when I choose "unchecked" in GUI it always jumps to 'Yes' (true). Is there anyway to force Rails to assign nil value also ?
Code:
f.input :confirmed, label: 'Confirmed', as: :radio_buttons, collection: [[ true, "Yes" ], [ false, "No" ], [ nil, "unchecked"]], label_method: :second, value_method: :first, selected: [ nil, 'unchecked' ]
Upvotes: 0
Views: 158
Reputation: 23
You can try use collection_radio_buttons:
<%= f.collection_radio_buttons(:confirmed, [[true, 'Yes'], [false, 'No'], [nil, 'unchecked']], :first, :second,{ checked: [nil, 'unchecked'] }) do |b| %>
<% b.label do %>
<%= b.radio_button %> <%= b.text %>
<% end %>
<% end %>
Upvotes: 0