Forum: Ruby on Rails beginner

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Luis S. (Guest)
on 2009-05-24 20: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
Freddy A. (Guest)
on 2009-05-24 21: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.
Frederick C. (Guest)
on 2009-05-24 22:16
(Received via mailing list)
On May 24, 6:29 pm, Freddy A. <removed_email_address@domain.invalid> 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.

Fred


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