Created
August 23, 2008 01:37
-
-
Save wycats/6885 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def update_unbound_check_box(attrs) | |
boolean = attrs[:boolean] || (attrs[:on] && attrs[:off]) ? true : false | |
case | |
when attrs.key?(:on) ^ attrs.key?(:off) | |
raise ArgumentError, ":on and :off must be specified together" | |
when (attrs[:boolean] == false) && (attrs.key?(:on)) | |
raise ArgumentError, ":boolean => false cannot be used with :on and :off" | |
when boolean && attrs.key?(:value) | |
raise ArgumentError, ":value can't be used with a boolean checkbox" | |
end | |
if attrs[:boolean] = boolean | |
attrs[:on] ||= "1"; attrs[:off] ||= "0" | |
end | |
if attrs[:checked] || (attrs[:on] && attrs[:on] == attrs[:value]) | |
attrs[:checked] = "checked" | |
else | |
attrs.delete(:checked) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment