Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails f.check_box set checked/unchecked values

so I got a form helper in rails with a checkbox; I want that checkbox to have values as "thatvalue" or "thisvalue" when checked or unchecked; I haven't found anywhere how to set this up with

f.check_box :field

I found something like that

<%= form.check_box :field, {}, "thisvalue", "thatvalue"  %>

but it doesn't work, because I also set :class and :style inside my tag, so having something like

<%= form.check_box :field, {}, "thisvalue", "thatvalue", :class => "checkbox", :style => "display:none;" %>

errors and tells me wrong number of arguments (5 for 4)

so right now I have to "hack" it in my controller, and set my field depending on if my checkbox is 0 or 1... which is pretty bad.

any idea?

like image 865
Jauny Avatar asked May 15 '13 19:05

Jauny


1 Answers

ok nevermind, I misunderstood the "options" field...

the answer is simply

<%= f.check_box :field, {:class => "myclass", :style => "mystyle"}, "checked-value", "unchecked-value" %>

and it works perfectly :)

like image 79
Jauny Avatar answered Sep 28 '22 04:09

Jauny