Forum: Ruby on Rails beginner

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E8ce3e2c0520fad995d01ab7064e66f9?d=identicon&s=25 Luis Sp (luis-sep)
on 2009-05-24 18:37
Hello everyone,
I'm new to RoR, and I have a silly problem I can't solve.
I have a User class, with some attributes (login, password, online..).
In the login form, I have a checkbox. I want to change the value of the
online attribute if this checkbox is checked. I know it must be
something like (if params[:checkboxname]==true).
Does anyone how to do that?

thanks a lot
4c438a80fc30661ad619ea177cf9cbd0?d=identicon&s=25 Freddy Andersen (Guest)
on 2009-05-24 19:30
(Received via mailing list)
if params[:checkbox]

This checks if that params is true(true/false, 1/0) or not, but how
did you do you checkbox code? If its just a form_for .. do |f|
f.checkbox(:checkbox) you should be ok.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-24 20:16
(Received via mailing list)
On May 24, 6:29 pm, Freddy Andersen <> wrote:
> if params[:checkbox]
> This checks if that params is true(true/false, 1/0)

both 1 and 0 are true in ruby :-)
If you are doing this by hand you will need to compare params
[:checkbox] to the value that gets submitted. if you are using the
check_box helper then by default the value will be "0" or
"1" (strings, not integers). If you are using check_box_tag or
crafting the html by hand then it is slightly more troublesome as if
the check box is not ticked there will be no value in the params hash.
If you are using the check_box helper it might be appropriate to just
pass the appropriate part of the params hash to update_attributes.


 or not, but how
This topic is locked and can not be replied to.