Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails simple form checkbox default to true

How do I make a simple for boolean checkbox default to true?

assign_client is a boolean field.

I tried these:

<%= f.input :assign_client, :label => 'Charge Client?', :true %>
<%= f.input :assign_client, :label => 'Charge Client?', :value => :true %>
<%= f.input :assign_client, :label => 'Charge Client?', :value => 1 %>

Thanks for the help!

like image 209
Reddirt Avatar asked Oct 25 '13 14:10

Reddirt


2 Answers

I think you should add input_html:

<%= f.input :assign_client, :label => 'Charge Client?', :input_html => { :checked => true }

proof

like image 185
zishe Avatar answered Nov 09 '22 15:11

zishe


Your second one will work fine just remove the : so it's a boolean value rather than a symbol.

<%= f.input :assign_client, :label => 'Charge Client?', :value => true %>
like image 26
gbdev Avatar answered Nov 09 '22 14:11

gbdev