Beginner


#1

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


#2

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.


#3

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 :slight_smile:
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