Default drop down selection only when no options selected

时间:2015-06-15 15:11:25

标签: ruby-on-rails ruby

I'd like to have a default option selected only if no other options have been selected. My current code is.

<%= f.association :acquiring_editors, collection: @aquiring_editor_options, wrapper: :no_label, selected: current_user.id %>

However, when I do select an alternative option it always reverts to the selected above. How do I only use the current user ID if no other option is selected?

1 个答案:

答案 0 :(得分:0)

如果您需要默认值,则需要||条件,这看起来像是:

selected: @thing.acquiring_editors_id || current_user_id

不确定这是什么对象,或者哪个字段可能表示选择了哪个,但这是一般的想法。