Search code examples
ruby-on-railssimple-form

simple_form turn boolean into dropdown with labels


I have a boolean column in my model. Say it's called isType1.

Now in my form, I would like to have a dropdown with two values (type1 if boolean is true, and type2 if boolean is false) instead of a checkbox or radio buttons.

Is that possible?

Right now I am displaying it as radio buttons:

<%= f.input :isType,  :as => :radio, :label => "Type"%>

I would prefer if I had a dropdown where the user could select type1 or type2 without changing the model to a string instead of a boolean.

Thanks.


Solution

  • This is what I was looking for:

    <%= f.input :isType, 
                :as => :select, 
                :collection => [['Type1',false],['Type2',true]], 
                :include_blank => false, 
                :label => "Type" %>