Match an option in select form with boolean values

前端 未结 2 1739
孤独总比滥情好
孤独总比滥情好 2021-02-12 13:31

I have the following piece of code

%br
= f.label :active, \'Status\'
= f.select :active, [\'Active\',\'Inactive\']

Symbol :active is a boolean

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-12 14:11

    A small extension of the earlier answer, if you're using a dropdown.

    I needed to use "options_for_select." Also, ":selected" stores the value for the next time you return to the form.

    <%= f.select(:active, options_for_select([['Active', true], ['Inactive', false]], {:selected => @symbol.active}),:prompt => "Select") %>
    

提交回复
热议问题