Created
January 11, 2012 23:58
-
-
Save avdi/1597569 to your computer and use it in GitHub Desktop.
Setting booleans in AR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When params come back from a form, checked boxes come back as 'field_name' => "on". | |
# So we can use that to update attributes, right? | |
model.field_name # => false | |
model.update_attribute(:field_name, "on") | |
model.field_name # => false | |
# WTF? |
So it turns out that the jQuery default value for checked boxes is "on"
.
The list of values ActiveRecord considers "truthy" for setting boolean attributes is: [true, 1, '1', 't', 'T', 'true', 'TRUE']
!@&%.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also,