0

I want to assign a value to a checkbox. The code below doesn't seem to work

Same Section <%= f.check_box :LSU_TYPE,  :value =>"Same Section" %>

Instead of storing 'Same Section' in the table, value '1' is stored when i check the box.

What am i doing wrong here?

2 Answers 2

4

A checkbox is a boolean field. It can only accept 1 or 0, 'True' or 'False'.

Sign up to request clarification or add additional context in comments.

1 Comment

-1 Not sure why this answer was accepted, A checkbox is just a way to select something, and that something may have any value. As per docs: "The checked_value defaults to 1 while the default unchecked_value is set to 0 which is convenient for boolean values"; however, any string value can be provided for both (as in @suely's example).
1

@Kum this works for me:

<div><%= f.label :pay_with_card? %></br>
<%= f.check_box :pay_with_card,{}, "Yes", "No"%>  

good luck!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.