0

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.

4

1 回答 1

1

唯一真正令人满意的答案是“使用带有提示的 collection_select”。

为 nil 创建表条目会产生各种无用成本的后果。

我理解关于“单选意味着选择某些东西”的观点,但是在某些情况下(具有非数组值的多个变量)可能会受益于具有单选按钮的 UI 视角:用户可以更轻松地同时比较不同的值而无需逐一激活每个下拉菜单一个。

于 2013-07-21T12:10:01.243 回答