Checkboxes

I’ve got a User model with an ActiveRecord method called ‘isAdmin’ that
determines wether or not that user is an administrator. And in order to
create these users I have new_user.rhtml paired with _user_form.rhtml,
in which there is a checkbox that is supposed to determine the value of
‘isAdmin’ - 0 or 1. I’ve tried several variations of things I found in
my Rails book and on the web, and absolutely nothing has worked thus
far. When I turn on validation in the User model, I keep getting told
that my checkbox is blank, which is impossible, since if it’s checked
isAdmin = 1 and if it’s not checked isAdmin = 0.

Any suggestions?

I’ve run across this. If you’re using the form_for(:model) format it
seems
to generate the necessary hidden input with value=0 whereas the
check_box_tag didn’t. If I recall correctly. Once I moved to the
form_for
format those kinds of problems haven’t popped up again.

Hope that helps.

RSL

Russell N. wrote:

I’ve run across this. If you’re using the form_for(:model) format it
seems
to generate the necessary hidden input with value=0 whereas the
check_box_tag didn’t. If I recall correctly. Once I moved to the
form_for
format those kinds of problems haven’t popped up again.

Hope that helps.

RSL

I tried the form_for model using this code and I’m still getting the
“isAdmin can’t be blank” error, despite the fact that I know that the
paramaters are being passed correctly, i.e. it shows me that I’m passing
isAdmin as either a 0 or a 1.

Anyway, here’s the code… ignore the html.

<% form_for :user, @user, :url => { :action => “create_user” } do |u| %>

Username: <%= u.text_field :name %> Password: <%= u.text_field :password %> Grant admin powers? <%= u.check_box :isAdmin %>
<% end %>