Jackson Cunningham
Jackson Cunningham

Reputation: 5073

Why are my unchecked f.check_boxes giving default value of "1" in rails?

I have a checkbox below. It's rendering properly (unchecked) but submitting with a value of "1". I want the unchecked boxes to have default values of 0.

<%= builder.check_box :content, :class=>"yesno", :data => {:'on-text' =>"YES", :'off-text' =>"NO", :question => question.id} %>

Thoughts?

Upvotes: 0

Views: 55

Answers (1)

Arup Rakshit
Arup Rakshit

Reputation: 118289

You need to do

<%= builder.check_box :content, {:class=>"yesno", :data => {:'on-text' =>"YES", :'off-text' =>"NO", :question => question.id}}, 0, 1 %>

As per the check_box documentation:

The checked_value defaults to 1 while the default unchecked_value is set to 0 which is convenient for boolean values.

Upvotes: 1

Related Questions