Match an option in select form with boolean values

前端 未结 2 1744
孤独总比滥情好
孤独总比滥情好 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:17

    You can provide a pair of values for each options: first will be used as label (inner text of tag), second will be used as a value attribute:

    = f.select :active, [['Active', true], ['Inactive', false]]
    

    It'll render something like:

    
    

    Have a look at the docs for select and options_for_select.

提交回复
热议问题