views:

53

answers:

4

I have an object: @object with tons of boolean fields.

now. according to the HTML spec, if a checkbox isn't checked, the value isn't sent.

Which is a problem... cause I need that information.

How do I get around that? the api for f.check_box suggests fields_for... http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M002298

but I couldn't figure out the syntax for @object.is_admin

=\

currently, without changing anything: i have this:

<% form_for @object do |f| %>
        <td><%= f.check_box :allow_downloads, :label => false  %></td>
.
.
.

error : undefined methodto_i' for #`

A: 

Are the automatically generated hidden fields for the checkboxes as described by that documentation not working for you?

John Topley
added some code to my post. the page renders nothing but the error.
DerNalia
A: 

It's nothing you should be concerned about.

If you look at the check_box helper generated code you'll see that rails creates a hidden field which represents the unchecked value. When you check the box, it will take precedence over the hidden field, because it's declared after it:

<input type="hidden" />
<input type="checkbox" />
vise
A: 

There is no '=' in the <% f.check_box. It should be <%= f.chec_box...

besides, if all fields are boolean, you can set them all to false, and only set true the ones passed through the request.

Angelus
aye, i noticed that... but that has nothing to do with my undefined methodto_i' error
DerNalia
well, in the bit of code you put there, there is not even a '#' symbol, I can't say what's wrong without seeing at at least the form :]probably it is a typo or something not being closed.
Angelus
A: 

The problem was that my was accessing the wrong controller. I moved my form to a proper view (made more sense for usability, anyway) and it works.

DerNalia