aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/tags/check_box.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-16 21:17:33 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-17 00:05:29 -0300
commit675fb8defdbfdabdd57298b760e701b0b5c74e48 (patch)
tree588cdafe9e895b4d897d31ae9ed60723fa2f688c /actionpack/lib/action_view/helpers/tags/check_box.rb
parentd6b9eb9b4417f1f8705284e520b796466a690ed6 (diff)
downloadrails-675fb8defdbfdabdd57298b760e701b0b5c74e48.tar.gz
rails-675fb8defdbfdabdd57298b760e701b0b5c74e48.tar.bz2
rails-675fb8defdbfdabdd57298b760e701b0b5c74e48.zip
Remove code duplication between CheckBox ans RadioButton
Diffstat (limited to 'actionpack/lib/action_view/helpers/tags/check_box.rb')
-rw-r--r--actionpack/lib/action_view/helpers/tags/check_box.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/check_box.rb b/actionpack/lib/action_view/helpers/tags/check_box.rb
index 55574e6f06..2cdc13524b 100644
--- a/actionpack/lib/action_view/helpers/tags/check_box.rb
+++ b/actionpack/lib/action_view/helpers/tags/check_box.rb
@@ -12,21 +12,15 @@ module ActionView
options = @options.stringify_keys
options["type"] = "checkbox"
options["value"] = @checked_value
+ options["checked"] = "checked" if input_checked?(object, options)
- if options.has_key?("checked")
- cv = options.delete "checked"
- checked = cv == true || cv == "checked"
- else
- checked = check_box_checked?(value(object))
- end
-
- options["checked"] = "checked" if checked
if options["multiple"]
add_default_name_and_id_for_value(@checked_value, options)
options.delete("multiple")
else
add_default_name_and_id(options)
end
+
hidden = @unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => @unchecked_value, "disabled" => options["disabled"]) : ""
checkbox = tag("input", options)
hidden + checkbox
@@ -34,7 +28,7 @@ module ActionView
private
- def check_box_checked?(value)
+ def checked?(value)
case value
when TrueClass, FalseClass
value