aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-16 23:15:07 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-17 00:05:30 -0300
commit7d2846b9dbb728d304347a8e70dbe845d4efbb35 (patch)
tree48c90fad69c4d92a37f963a534c5a35fa24e8302 /actionpack/lib/action_view
parent9eb6cd6373cf8c1142e1f3cd9e3af55d47828bd7 (diff)
downloadrails-7d2846b9dbb728d304347a8e70dbe845d4efbb35.tar.gz
rails-7d2846b9dbb728d304347a8e70dbe845d4efbb35.tar.bz2
rails-7d2846b9dbb728d304347a8e70dbe845d4efbb35.zip
Extract GroupedCollectionSelect
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb8
-rw-r--r--actionpack/lib/action_view/helpers/tags.rb35
-rw-r--r--actionpack/lib/action_view/helpers/tags/grouped_collection_select.rb24
3 files changed, 43 insertions, 24 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index b3a704780c..8cacbbd791 100644
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -239,7 +239,7 @@ module ActionView
# </select>
#
def grouped_collection_select(object, method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
- InstanceTag.new(object, method, self, options.delete(:object)).to_grouped_collection_select_tag(collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
+ ActionView::Helpers::Tags::GroupedCollectionSelect.new(object, method, self, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options).render
end
# Return select and option tags for the given object and method, using
@@ -575,12 +575,6 @@ module ActionView
class InstanceTag #:nodoc:
include FormOptionsHelper
- def to_grouped_collection_select_tag(collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
- select_content_tag(
- option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, value(object)), options, html_options
- )
- end
-
def to_time_zone_select_tag(priority_zones, options, html_options)
select_content_tag(
time_zone_options_for_select(value(object) || options[:default], priority_zones, options[:model] || ActiveSupport::TimeZone), options, html_options
diff --git a/actionpack/lib/action_view/helpers/tags.rb b/actionpack/lib/action_view/helpers/tags.rb
index 9fe373f8c9..5f94a177fd 100644
--- a/actionpack/lib/action_view/helpers/tags.rb
+++ b/actionpack/lib/action_view/helpers/tags.rb
@@ -1,23 +1,24 @@
module ActionView
module Helpers
module Tags
- autoload :Base, 'action_view/helpers/tags/base'
- autoload :Label, 'action_view/helpers/tags/label'
- autoload :TextField, 'action_view/helpers/tags/text_field'
- autoload :PasswordField, 'action_view/helpers/tags/password_field'
- autoload :HiddenField, 'action_view/helpers/tags/hidden_field'
- autoload :FileField, 'action_view/helpers/tags/file_field'
- autoload :SearchField, 'action_view/helpers/tags/search_field'
- autoload :TelField, 'action_view/helpers/tags/tel_field'
- autoload :UrlField, 'action_view/helpers/tags/url_field'
- autoload :EmailField, 'action_view/helpers/tags/email_field'
- autoload :NumberField, 'action_view/helpers/tags/number_field'
- autoload :RangeField, 'action_view/helpers/tags/range_field'
- autoload :TextArea, 'action_view/helpers/tags/text_area'
- autoload :CheckBox, 'action_view/helpers/tags/check_box'
- autoload :RadioButton, 'action_view/helpers/tags/radio_button'
- autoload :Select, 'action_view/helpers/tags/select'
- autoload :CollectionSelect, 'action_view/helpers/tags/collection_select'
+ autoload :Base, 'action_view/helpers/tags/base'
+ autoload :Label, 'action_view/helpers/tags/label'
+ autoload :TextField, 'action_view/helpers/tags/text_field'
+ autoload :PasswordField, 'action_view/helpers/tags/password_field'
+ autoload :HiddenField, 'action_view/helpers/tags/hidden_field'
+ autoload :FileField, 'action_view/helpers/tags/file_field'
+ autoload :SearchField, 'action_view/helpers/tags/search_field'
+ autoload :TelField, 'action_view/helpers/tags/tel_field'
+ autoload :UrlField, 'action_view/helpers/tags/url_field'
+ autoload :EmailField, 'action_view/helpers/tags/email_field'
+ autoload :NumberField, 'action_view/helpers/tags/number_field'
+ autoload :RangeField, 'action_view/helpers/tags/range_field'
+ autoload :TextArea, 'action_view/helpers/tags/text_area'
+ autoload :CheckBox, 'action_view/helpers/tags/check_box'
+ autoload :RadioButton, 'action_view/helpers/tags/radio_button'
+ autoload :Select, 'action_view/helpers/tags/select'
+ autoload :CollectionSelect, 'action_view/helpers/tags/collection_select'
+ autoload :GroupedCollectionSelect, 'action_view/helpers/tags/grouped_collection_select'
end
end
end
diff --git a/actionpack/lib/action_view/helpers/tags/grouped_collection_select.rb b/actionpack/lib/action_view/helpers/tags/grouped_collection_select.rb
new file mode 100644
index 0000000000..507466a57a
--- /dev/null
+++ b/actionpack/lib/action_view/helpers/tags/grouped_collection_select.rb
@@ -0,0 +1,24 @@
+module ActionView
+ module Helpers
+ module Tags
+ class GroupedCollectionSelect < Base #:nodoc:
+ def initialize(object_name, method_name, template_object, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
+ @collection = collection
+ @group_method = group_method
+ @group_label_method = group_label_method
+ @option_key_method = option_key_method
+ @option_value_method = option_value_method
+ @html_options = html_options
+
+ super(object_name, method_name, template_object, options)
+ end
+
+ def render
+ select_content_tag(
+ option_groups_from_collection_for_select(@collection, @group_method, @group_label_method, @option_key_method, @option_value_method, value(@object)), @options, @html_options
+ )
+ end
+ end
+ end
+ end
+end