Whatever I do, whether check or not check, the value stored in the
database is always 1, I have tried setting different default values but
nothing seems to help.
Can you advise what I'm doing wrong please? Thank ou
Whatever I do, whether check or not check, the value stored in the
database is always 1, I have tried setting different default values but
nothing seems to help.
Can you advise what I'm doing wrong please? Thank ou
What's in your controller ? Does the sql being executed look sane ?
Whatever I do, whether check or not check, the value stored in the
database is always 1, I have tried setting different default values but
nothing seems to help.
Can you advise what I'm doing wrong please? Thank ou
What's in your controller ? Does the sql being executed look sane ?
So have you figured out where this is going wrong ? Do the parameters
that you see in the log look ok ? Does the sql your app execute ok ?
Have you tried stepping through your app with the debugger to pinpoint
where things are going wrong ?
You -cannot- have two input fields both containing the same name
value.
I assume the value from the last input field will be the one the
browser uses.
You have:
<input id="service_Monday"
name="service[Monday]" type="checkbox" value="1" />
Which means that even if it is not checked, the checkbox will return a
value of 1. And being the last input with that name, your form will
always have the value=1.
What I think would be more helpful is:
<input type=checkbox ... checked /> (not value="1")
Also, write an javascript function that is fired onsubmit that checks
both the checkbox and the hidden value and stores the approprite value
in the parameter before it goes to the server.
Not true, and including the same parameter more than once is actually
quite common.
Rails adds the hidden input tag for you on purpose. It's to get around
the
problem that when a checkbox is left unchecked, browsers don't even
send the
form parameter in the request. So if the checkbox is left unchecked,
you'll get
one value sent for the parameter - the "0" defined in the hidden
field. If you
check the box, you get two values sent - the "0" from the hidden
field, and
"1" for the check box, in that order. The latter will overwrite the
former in
Rails' (i.e. Rack's) parameter munging code.