aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2012-02-14 01:28:22 -0800
committerJosé Valim <jose.valim@plataformatec.com.br>2012-02-14 01:28:22 -0800
commit65ffcec5a64053576b2597d3e40fd1d0176c7129 (patch)
tree3e5ed23429f8c403ea005cefaf5c66e569e8d691 /actionpack/lib/action_view
parentc5b90a6ab1430107131f0cb363e2697a4ecb2714 (diff)
parenta10ed70999935cf86bd9a170ce3d4748631968ca (diff)
downloadrails-65ffcec5a64053576b2597d3e40fd1d0176c7129.tar.gz
rails-65ffcec5a64053576b2597d3e40fd1d0176c7129.tar.bz2
rails-65ffcec5a64053576b2597d3e40fd1d0176c7129.zip
Merge pull request #5032 from carlosantoniodasilva/collection-helpers-object
Allow collection helpers with block to access current object in the collection
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb4
-rw-r--r--actionpack/lib/action_view/helpers/tags/collection_helpers.rb11
-rw-r--r--actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb4
3 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 5f1e9ec026..e23f5113fb 100644
--- a/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb
+++ b/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb
@@ -14,9 +14,9 @@ module ActionView
end
def render
- rendered_collection = render_collection do |value, text, default_html_options|
+ rendered_collection = render_collection do |item, value, text, default_html_options|
default_html_options[:multiple] = true
- builder = instantiate_builder(CheckBoxBuilder, value, text, default_html_options)
+ builder = instantiate_builder(CheckBoxBuilder, item, value, text, default_html_options)
if block_given?
yield builder
diff --git a/actionpack/lib/action_view/helpers/tags/collection_helpers.rb b/actionpack/lib/action_view/helpers/tags/collection_helpers.rb
index 1e2e77dde1..6f950e552a 100644
--- a/actionpack/lib/action_view/helpers/tags/collection_helpers.rb
+++ b/actionpack/lib/action_view/helpers/tags/collection_helpers.rb
@@ -3,13 +3,14 @@ module ActionView
module Tags
module CollectionHelpers
class Builder
- attr_reader :text, :value
+ attr_reader :object, :text, :value
- def initialize(template_object, object_name, method_name,
+ def initialize(template_object, object_name, method_name, object,
sanitized_attribute_name, text, value, input_html_options)
@template_object = template_object
@object_name = object_name
@method_name = method_name
+ @object = object
@sanitized_attribute_name = sanitized_attribute_name
@text = text
@value = value
@@ -32,8 +33,8 @@ module ActionView
private
- def instantiate_builder(builder_class, value, text, html_options)
- builder_class.new(@template_object, @object_name, @method_name,
+ def instantiate_builder(builder_class, item, value, text, html_options)
+ builder_class.new(@template_object, @object_name, @method_name, item,
sanitize_attribute_name(value), text, value, html_options)
end
@@ -71,7 +72,7 @@ module ActionView
text = value_for_collection(item, @text_method)
default_html_options = default_html_options_for_collection(item, value)
- yield value, text, default_html_options
+ yield item, value, text, default_html_options
end.join.html_safe
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 8e7aeeed63..ba2035f074 100644
--- a/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb
+++ b/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb
@@ -14,8 +14,8 @@ module ActionView
end
def render
- render_collection do |value, text, default_html_options|
- builder = instantiate_builder(RadioButtonBuilder, value, text, default_html_options)
+ render_collection do |item, value, text, default_html_options|
+ builder = instantiate_builder(RadioButtonBuilder, item, value, text, default_html_options)
if block_given?
yield builder