stupid checkboxes

Hi Vince,

Vince W. wrote:

I'm trying to pass a true/false from my account/signup
page to the account controller but I can't even get the
checkbox to work on the view itself.


Here's the code:

<%= check_box_tag 'user', 'user_type', :checked => 'checked' %>

For starters, you're passing the arguments for check_box, not check_box_tag. In case you don't have the URL, it's Look in the bottom left panel (methods).

<% warn @user.user_type %>

Simple, eh? I figure that the @user.user_type
would give me a 1 or 0 or true or false or
*something* but all I get is nil. So @user.user_type?
always yields false no matter whether the
checkbox is ticked or not.

Rails view code produces html that will be served back to the visitor's browser for display. It looks like you're expecting JS-like behavior. When the code in your view is executed, nothing has been entered by the user. Thus your nil result. One 'rule of thumb' I developed / found helpful early on is that instance variables are for 'pushing' info *to* the visitor's brower, and params are for 'pulling' info the visitor enters *from* the browser back in to the app.

Also tried it with just plain check_box but
the same thing happens.

Don't know exactly what you mean by 'tried'. Did you, for example, also switch from 'start_form' to 'start_form_tag'? It needs to be consistent.

It can't be that hard, can it?

Once you get in the flow, it's incredibly easy. Swimmin' upstream sucks, though.

Best regards,