Question

A set of mutually-exclusive attributes need to be selected, thus via a radio_button.

  <% @finitures.each do |finiture| %>
    <%= f.radio_button :finitura_stampa, finiture %> <%= finiture.nome %><br />
  <% end %>

However, NIL is an allowed value.

One way to handle this is to create a dummy record that tries to be invisible, but that's not very clean. A better way would be to have a radio button with a label 'None' that sets the attribute to NIL.

I have not found a way to do this.

Was it helpful?

Solution

The only real satisfactory answer is 'use collection_select with a prompt'.

Creating a table entry for nil creates all sorts of consequences which are useless costs.

I understand the point about 'radio means selecting something', however in some contexts (multiple variables with non-array values) may benefit from a UI perspective of having radio buttons: users can more easily compare different values simultaneously without activating one-by-one each pullDown menu.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top