0

I want to save multiple check box category[] into database :-

<label><%= f.check_box :category,{class: 'chk'},1,0%>Apple</label>
<label><%= f.check_box :category,{class: 'chk'},1,0%>Orange</label>
<label><%= f.check_box :category,{class: 'chk'},1,0%>Banana</label>

Here my create form Edit form

controller

database structure

1
  • What is your problem? If you want to store something in a database, just do it Commented Jun 11, 2020 at 16:56

1 Answer 1

1

There is a :multiple option, if that's what you need? It's hard to understand exactly what you want

    check_box("puppy", "commands", {:multiple => true}, "sit", nil)
    check_box("puppy", "commands", {:multiple => true}, "fetch", nil)
    check_box("puppy", "commands", {:multiple => true}, "roll_over", nil)

Further examples here: https://apidock.com/rails/ActionView/Helpers/FormHelper/check_box

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

1 Comment

Your solution can save data with multiple array. I also would like to know if I checked Apple and Orange in registration form, it also checked Apple and Orange in edit form untile I change checkbox uncheck.

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.