diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-01 10:59:12 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-02 09:40:24 -0200 |
commit | c988aaf69086af78dcb6eebf357e1149fc45e2ac (patch) | |
tree | 885f9580fa6aa7892fffc4cb6241a76c8fee312b /actionpack/lib | |
parent | b17be2938c4a05d29226e0dc189251014ccd5d2c (diff) | |
download | rails-c988aaf69086af78dcb6eebf357e1149fc45e2ac.tar.gz rails-c988aaf69086af78dcb6eebf357e1149fc45e2ac.tar.bz2 rails-c988aaf69086af78dcb6eebf357e1149fc45e2ac.zip |
Refactor collection helpers to extract radio/checkbox/label calls
[Carlos Antonio da Silva + Rafael Mendonça França]
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb | 14 |
2 files changed, 18 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb index 7c85441c5d..36a7e24011 100644 --- a/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -2,8 +2,6 @@ module ActionView module Helpers module Tags class CollectionCheckBoxes < CollectionRadioButtons - delegate :check_box, :label, :to => :@template_object - def render rendered_collection = render_collection do |value, text, default_html_options| default_html_options[:multiple] = true @@ -11,8 +9,8 @@ module ActionView if block_given? yield sanitize_attribute_name(value), text, value, default_html_options else - check_box(@object_name, @method_name, default_html_options, value, nil) + - label(@object_name, sanitize_attribute_name(value), text, :class => "collection_check_boxes") + check_box(value, default_html_options) + + label(value, text, "collection_check_boxes") end end @@ -22,6 +20,12 @@ module ActionView rendered_collection + hidden end + + private + + def check_box(value, html_options) + @template_object.check_box(@object_name, @method_name, html_options, value, nil) + end end end end diff --git a/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb b/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb index 3d04ae3579..60d017cfe5 100644 --- a/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb +++ b/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb @@ -2,21 +2,27 @@ module ActionView module Helpers module Tags class CollectionRadioButtons < CollectionSelect - delegate :radio_button, :label, :to => :@template_object - def render render_collection do |value, text, default_html_options| if block_given? yield sanitize_attribute_name(value), text, value, default_html_options else - radio_button(@object_name, @method_name, value, default_html_options) + - label(@object_name, sanitize_attribute_name(value), text, :class => "collection_radio_buttons") + radio_button(value, default_html_options) + + label(value, text, "collection_radio_buttons") end end end private + def radio_button(value, html_options) + @template_object.radio_button(@object_name, @method_name, value, html_options) + end + + def label(value, text, css_class) + @template_object.label(@object_name, sanitize_attribute_name(value), text, :class => css_class) + end + # Generate default options for collection helpers, such as :checked and # :disabled. def default_html_options_for_collection(item, value) #:nodoc: |