diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-01 16:14:24 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-02 09:40:24 -0200 |
commit | 17d214a1d4c71db39d2a4cab4d18ccea9f5b8ab5 (patch) | |
tree | 77eb411483d90accbc1f3b009a4d0a48a706bdf5 /actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb | |
parent | c988aaf69086af78dcb6eebf357e1149fc45e2ac (diff) | |
download | rails-17d214a1d4c71db39d2a4cab4d18ccea9f5b8ab5.tar.gz rails-17d214a1d4c71db39d2a4cab4d18ccea9f5b8ab5.tar.bz2 rails-17d214a1d4c71db39d2a4cab4d18ccea9f5b8ab5.zip |
Create a Builder factory class to use with collection helpers + block
This will make it easy for the user to handle how check box/radio and
labels should be generated, abstracting any text/value/default html
options required to make it work.
[Carlos Antonio da Silva + Rafael Mendonça França]
Diffstat (limited to 'actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb | 19 |
1 files changed, 10 insertions, 9 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 36a7e24011..92312c5081 100644 --- a/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -2,15 +2,22 @@ module ActionView module Helpers module Tags class CollectionCheckBoxes < CollectionRadioButtons + class CheckBoxBuilder < Builder + def check_box(extra_html_options={}) + html_options = extra_html_options.merge(@input_html_options) + @template_object.check_box(@object_name, @method_name, html_options, @value, nil) + end + end + def render rendered_collection = render_collection do |value, text, default_html_options| default_html_options[:multiple] = true + builder = instantiate_builder(CheckBoxBuilder, value, text, default_html_options) if block_given? - yield sanitize_attribute_name(value), text, value, default_html_options + yield builder else - check_box(value, default_html_options) + - label(value, text, "collection_check_boxes") + builder.check_box + builder.label(:class => "collection_check_boxes") end end @@ -20,12 +27,6 @@ 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 |