The Rails simple form checkbox is set to true by default.

How to make simple for boolean flag by default equal true?

assign_client is a boolean field.

I tried:

 <%= 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!

+6
source share
2 answers

I think you should add input_html :

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

evidence

+11
source

Your second one will work fine, just delete : so that it is a boolean and not a symbol.

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

Source: https://habr.com/ru/post/956723/


All Articles