form_options_helper.rb
Upload User: whfwc2
Upload Date: 2018-05-21
Package Size: 3090k
Code Size: 24k
Category:

Java Books

Development Platform:

Unix_Linux

  1. require 'cgi'
  2. require 'erb'
  3. require 'action_view/helpers/form_helper'
  4. module ActionView
  5.   module Helpers
  6.     # Provides a number of methods for turning different kinds of containers into a set of option tags.
  7.     # == Options
  8.     # The <tt>collection_select</tt>, <tt>country_select</tt>, <tt>select</tt>,
  9.     # and <tt>time_zone_select</tt> methods take an <tt>options</tt> parameter,
  10.     # a hash.
  11.     #
  12.     # * <tt>:include_blank</tt> - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.
  13.     #
  14.     # For example,
  15.     #
  16.     #   select("post", "category", Post::CATEGORIES, {:include_blank => true})
  17.     #
  18.     # could become:
  19.     #
  20.     #   <select name="post[category]">
  21.     #     <option></option>
  22.     #     <option>joke</option>
  23.     #     <option>poem</option>
  24.     #   </select>
  25.     #
  26.     # Another common case is a select tag for an <tt>belongs_to</tt>-associated object.
  27.     #
  28.     # Example with @post.person_id => 2:
  29.     #
  30.     #   select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] }, {:include_blank => 'None'})
  31.     #
  32.     # could become:
  33.     #
  34.     #   <select name="post[person_id]">
  35.     #     <option value="">None</option>
  36.     #     <option value="1">David</option>
  37.     #     <option value="2" selected="selected">Sam</option>
  38.     #     <option value="3">Tobias</option>
  39.     #   </select>
  40.     #
  41.     # * <tt>:prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this prepends an option with a generic prompt -- "Please select" -- or the given prompt string.
  42.     #
  43.     # Example:
  44.     #
  45.     #   select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] }, {:prompt => 'Select Person'})
  46.     #
  47.     # could become:
  48.     #
  49.     #   <select name="post[person_id]">
  50.     #     <option value="">Select Person</option>
  51.     #     <option value="1">David</option>
  52.     #     <option value="2">Sam</option>
  53.     #     <option value="3">Tobias</option>
  54.     #   </select>
  55.     # 
  56.     # Like the other form helpers, +select+ can accept an <tt>:index</tt> option to manually set the ID used in the resulting output. Unlike other helpers, +select+ expects this 
  57.     # option to be in the +html_options+ parameter.
  58.     # 
  59.     # Example: 
  60.     # 
  61.     #   select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
  62.     # 
  63.     # becomes:
  64.     # 
  65.     #   <select name="album[][genre]" id="album__genre">
  66.     #     <option value="rap">rap</option>
  67.     #     <option value="rock">rock</option>
  68.     #     <option value="country">country</option>
  69.     #   </select>
  70.     module FormOptionsHelper
  71.       include ERB::Util
  72.       # Create a select tag and a series of contained option tags for the provided object and method.
  73.       # The option currently held by the object will be selected, provided that the object is available.
  74.       # See options_for_select for the required format of the choices parameter.
  75.       #
  76.       # Example with @post.person_id => 1:
  77.       #   select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] }, { :include_blank => true })
  78.       #
  79.       # could become:
  80.       #
  81.       #   <select name="post[person_id]">
  82.       #     <option value=""></option>
  83.       #     <option value="1" selected="selected">David</option>
  84.       #     <option value="2">Sam</option>
  85.       #     <option value="3">Tobias</option>
  86.       #   </select>
  87.       #
  88.       # This can be used to provide a default set of options in the standard way: before rendering the create form, a
  89.       # new model instance is assigned the default options and bound to @model_name. Usually this model is not saved
  90.       # to the database. Instead, a second model object is created when the create request is received.
  91.       # This allows the user to submit a form page more than once with the expected results of creating multiple records.
  92.       # In addition, this allows a single partial to be used to generate form inputs for both edit and create forms.
  93.       #
  94.       # By default, <tt>post.person_id</tt> is the selected option.  Specify <tt>:selected => value</tt> to use a different selection
  95.       # or <tt>:selected => nil</tt> to leave all options unselected.
  96.       def select(object, method, choices, options = {}, html_options = {})
  97.         InstanceTag.new(object, method, self, nil, options.delete(:object)).to_select_tag(choices, options, html_options)
  98.       end
  99.       # Returns <tt><select></tt> and <tt><option></tt> tags for the collection of existing return values of
  100.       # +method+ for +object+'s class. The value returned from calling +method+ on the instance +object+ will
  101.       # be selected. If calling +method+ returns +nil+, no selection is made without including <tt>:prompt</tt>
  102.       # or <tt>:include_blank</tt> in the +options+ hash.
  103.       #
  104.       # The <tt>:value_method</tt> and <tt>:text_method</tt> parameters are methods to be called on each member
  105.       # of +collection+. The return values are used as the +value+ attribute and contents of each
  106.       # <tt><option></tt> tag, respectively.
  107.       # 
  108.       # Example object structure for use with this method:
  109.       #   class Post < ActiveRecord::Base
  110.       #     belongs_to :author
  111.       #   end
  112.       #   class Author < ActiveRecord::Base
  113.       #     has_many :posts
  114.       #     def name_with_initial
  115.       #       "#{first_name.first}. #{last_name}"
  116.       #     end
  117.       #   end
  118.       #
  119.       # Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):
  120.       #   collection_select(:post, :author_id, Author.find(:all), :id, :name_with_initial, {:prompt => true})
  121.       #
  122.       # If <tt>@post.author_id</tt> is already <tt>1</tt>, this would return:
  123.       #   <select name="post[author_id]">
  124.       #     <option value="">Please select</option>
  125.       #     <option value="1" selected="selected">D. Heinemeier Hansson</option>
  126.       #     <option value="2">D. Thomas</option>
  127.       #     <option value="3">M. Clark</option>
  128.       #   </select>
  129.       def collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
  130.         InstanceTag.new(object, method, self, nil, options.delete(:object)).to_collection_select_tag(collection, value_method, text_method, options, html_options)
  131.       end
  132.       # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
  133.       def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
  134.         InstanceTag.new(object, method, self, nil, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
  135.       end
  136.       # Return select and option tags for the given object and method, using
  137.       # #time_zone_options_for_select to generate the list of option tags.
  138.       #
  139.       # In addition to the <tt>:include_blank</tt> option documented above,
  140.       # this method also supports a <tt>:model</tt> option, which defaults
  141.       # to TimeZone. This may be used by users to specify a different time
  142.       # zone model object. (See +time_zone_options_for_select+ for more
  143.       # information.)
  144.       #
  145.       # You can also supply an array of TimeZone objects
  146.       # as +priority_zones+, so that they will be listed above the rest of the
  147.       # (long) list. (You can use TimeZone.us_zones as a convenience for
  148.       # obtaining a list of the US time zones.)
  149.       #
  150.       # Finally, this method supports a <tt>:default</tt> option, which selects
  151.       # a default TimeZone if the object's time zone is +nil+.
  152.       #
  153.       # Examples:
  154.       #   time_zone_select( "user", "time_zone", nil, :include_blank => true)
  155.       #
  156.       #   time_zone_select( "user", "time_zone", nil, :default => "Pacific Time (US & Canada)" )
  157.       #
  158.       #   time_zone_select( "user", 'time_zone', TimeZone.us_zones, :default => "Pacific Time (US & Canada)")
  159.       #
  160.       #   time_zone_select( "user", 'time_zone', [ TimeZone['Alaska'], TimeZone['Hawaii'] ])
  161.       #
  162.       #   time_zone_select( "user", "time_zone", TZInfo::Timezone.all.sort, :model => TZInfo::Timezone)
  163.       def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {})
  164.         InstanceTag.new(object, method, self, nil, options.delete(:object)).to_time_zone_select_tag(priority_zones, options, html_options)
  165.       end
  166.       # Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container
  167.       # where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and
  168.       # the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values
  169.       # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag.  +selected+
  170.       # may also be an array of values to be selected when using a multiple select.
  171.       #
  172.       # Examples (call, result):
  173.       #   options_for_select([["Dollar", "$"], ["Kroner", "DKK"]])
  174.       #     <option value="$">Dollar</option>n<option value="DKK">Kroner</option>
  175.       #
  176.       #   options_for_select([ "VISA", "MasterCard" ], "MasterCard")
  177.       #     <option>VISA</option>n<option selected="selected">MasterCard</option>
  178.       #
  179.       #   options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40")
  180.       #     <option value="$20">Basic</option>n<option value="$40" selected="selected">Plus</option>
  181.       #
  182.       #   options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"])
  183.       #     <option selected="selected">VISA</option>n<option>MasterCard</option>n<option selected="selected">Discover</option>
  184.       #
  185.       # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
  186.       def options_for_select(container, selected = nil)
  187.         container = container.to_a if Hash === container
  188.         options_for_select = container.inject([]) do |options, element|
  189.           text, value = option_text_and_value(element)
  190.           selected_attribute = ' selected="selected"' if option_value_selected?(value, selected)
  191.           options << %(<option value="#{html_escape(value.to_s)}"#{selected_attribute}>#{html_escape(text.to_s)}</option>)
  192.         end
  193.         options_for_select.join("n")
  194.       end
  195.       # Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the
  196.       # the result of a call to the +value_method+ as the option value and the +text_method+ as the option text.
  197.       # If +selected+ is specified, the element returning a match on +value_method+ will get the selected option tag.
  198.       #
  199.       # Example (call, result). Imagine a loop iterating over each +person+ in <tt>@project.people</tt> to generate an input tag:
  200.       #   options_from_collection_for_select(@project.people, "id", "name")
  201.       #     <option value="#{person.id}">#{person.name}</option>
  202.       #
  203.       # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
  204.       def options_from_collection_for_select(collection, value_method, text_method, selected = nil)
  205.         options = collection.map do |element|
  206.           [element.send(text_method), element.send(value_method)]
  207.         end
  208.         options_for_select(options, selected)
  209.       end
  210.       # Returns a string of <tt><option></tt> tags, like <tt>options_from_collection_for_select</tt>, but
  211.       # groups them by <tt><optgroup></tt> tags based on the object relationships of the arguments.
  212.       #
  213.       # Parameters:
  214.       # * +collection+ - An array of objects representing the <tt><optgroup></tt> tags.
  215.       # * +group_method+ - The name of a method which, when called on a member of +collection+, returns an
  216.       #   array of child objects representing the <tt><option></tt> tags.
  217.       # * group_label_method+ - The name of a method which, when called on a member of +collection+, returns a
  218.       #   string to be used as the +label+ attribute for its <tt><optgroup></tt> tag.
  219.       # * +option_key_method+ - The name of a method which, when called on a child object of a member of
  220.       #   +collection+, returns a value to be used as the +value+ attribute for its <tt><option></tt> tag.
  221.       # * +option_value_method+ - The name of a method which, when called on a child object of a member of
  222.       #   +collection+, returns a value to be used as the contents of its <tt><option></tt> tag.
  223.       # * +selected_key+ - A value equal to the +value+ attribute for one of the <tt><option></tt> tags,
  224.       #   which will have the +selected+ attribute set. Corresponds to the return value of one of the calls
  225.       #   to +option_key_method+. If +nil+, no selection is made.
  226.       #
  227.       # Example object structure for use with this method:
  228.       #   class Continent < ActiveRecord::Base
  229.       #     has_many :countries
  230.       #     # attribs: id, name
  231.       #   end
  232.       #   class Country < ActiveRecord::Base
  233.       #     belongs_to :continent
  234.       #     # attribs: id, name, continent_id
  235.       #   end
  236.       #
  237.       # Sample usage:
  238.       #   option_groups_from_collection_for_select(@continents, :countries, :name, :id, :name, 3)
  239.       #
  240.       # Possible output:
  241.       #   <optgroup label="Africa">
  242.       #     <option value="1">Egypt</option>
  243.       #     <option value="4">Rwanda</option>
  244.       #     ...
  245.       #   </optgroup>
  246.       #   <optgroup label="Asia">
  247.       #     <option value="3" selected="selected">China</option>
  248.       #     <option value="12">India</option>
  249.       #     <option value="5">Japan</option>
  250.       #     ...
  251.       #   </optgroup>
  252.       #
  253.       # <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to
  254.       # wrap the output in an appropriate <tt><select></tt> tag.
  255.       def option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil)
  256.         collection.inject("") do |options_for_select, group|
  257.           group_label_string = eval("group.#{group_label_method}")
  258.           options_for_select += "<optgroup label="#{html_escape(group_label_string)}">"
  259.           options_for_select += options_from_collection_for_select(eval("group.#{group_method}"), option_key_method, option_value_method, selected_key)
  260.           options_for_select += '</optgroup>'
  261.         end
  262.       end
  263.       # Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
  264.       # have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
  265.       # that they will be listed above the rest of the (long) list.
  266.       #
  267.       # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
  268.       def country_options_for_select(selected = nil, priority_countries = nil)
  269.         country_options = ""
  270.         if priority_countries
  271.           country_options += options_for_select(priority_countries, selected)
  272.           country_options += "<option value="" disabled="disabled">-------------</option>n"
  273.         end
  274.         return country_options + options_for_select(COUNTRIES, selected)
  275.       end
  276.       # Returns a string of option tags for pretty much any time zone in the
  277.       # world. Supply a TimeZone name as +selected+ to have it marked as the
  278.       # selected option tag. You can also supply an array of TimeZone objects
  279.       # as +priority_zones+, so that they will be listed above the rest of the
  280.       # (long) list. (You can use TimeZone.us_zones as a convenience for
  281.       # obtaining a list of the US time zones.)
  282.       #
  283.       # The +selected+ parameter must be either +nil+, or a string that names
  284.       # a TimeZone.
  285.       #
  286.       # By default, +model+ is the TimeZone constant (which can be obtained
  287.       # in Active Record as a value object). The only requirement is that the
  288.       # +model+ parameter be an object that responds to +all+, and returns
  289.       # an array of objects that represent time zones.
  290.       #
  291.       # NOTE: Only the option tags are returned, you have to wrap this call in
  292.       # a regular HTML select tag.
  293.       def time_zone_options_for_select(selected = nil, priority_zones = nil, model = ::ActiveSupport::TimeZone)
  294.         zone_options = ""
  295.         zones = model.all
  296.         convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } }
  297.         if priority_zones
  298.           zone_options += options_for_select(convert_zones[priority_zones], selected)
  299.           zone_options += "<option value="" disabled="disabled">-------------</option>n"
  300.           zones = zones.reject { |z| priority_zones.include?( z ) }
  301.         end
  302.         zone_options += options_for_select(convert_zones[zones], selected)
  303.         zone_options
  304.       end
  305.       private
  306.         def option_text_and_value(option)
  307.           # Options are [text, value] pairs or strings used for both.
  308.           if !option.is_a?(String) and option.respond_to?(:first) and option.respond_to?(:last)
  309.             [option.first, option.last]
  310.           else
  311.             [option, option]
  312.           end
  313.         end
  314.         def option_value_selected?(value, selected)
  315.           if selected.respond_to?(:include?) && !selected.is_a?(String)
  316.             selected.include? value
  317.           else
  318.             value == selected
  319.           end
  320.         end
  321.         # All the countries included in the country_options output.
  322.         COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
  323.           "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
  324.           "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
  325.           "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil",
  326.           "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
  327.           "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
  328.           "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
  329.           "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
  330.           "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
  331.           "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)",
  332.           "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
  333.           "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea",
  334.           "Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)",
  335.           "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
  336.           "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
  337.           "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
  338.           "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya",
  339.           "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
  340.           "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
  341.           "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
  342.           "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
  343.           "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
  344.           "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
  345.           "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
  346.           "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
  347.           "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
  348.           "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
  349.           "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
  350.           "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
  351.           "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname",
  352.           "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
  353.           "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
  354.           "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
  355.           "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
  356.           "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela",
  357.           "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara",
  358.           "Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
  359.     end
  360.     class InstanceTag #:nodoc:
  361.       include FormOptionsHelper
  362.       def to_select_tag(choices, options, html_options)
  363.         html_options = html_options.stringify_keys
  364.         add_default_name_and_id(html_options)
  365.         value = value(object)
  366.         selected_value = options.has_key?(:selected) ? options[:selected] : value
  367.         content_tag("select", add_options(options_for_select(choices, selected_value), options, selected_value), html_options)
  368.       end
  369.       def to_collection_select_tag(collection, value_method, text_method, options, html_options)
  370.         html_options = html_options.stringify_keys
  371.         add_default_name_and_id(html_options)
  372.         value = value(object)
  373.         content_tag(
  374.           "select", add_options(options_from_collection_for_select(collection, value_method, text_method, value), options, value), html_options
  375.         )
  376.       end
  377.       def to_country_select_tag(priority_countries, options, html_options)
  378.         ActiveSupport::Deprecation.warn("country_select will be removed from 2.2.0.  http://www.rubyonrails.org/deprecation/list-of-countries has more information.", caller)
  379.         html_options = html_options.stringify_keys
  380.         add_default_name_and_id(html_options)
  381.         value = value(object)
  382.         content_tag("select",
  383.           add_options(
  384.             country_options_for_select(value, priority_countries),
  385.             options, value
  386.           ), html_options
  387.         )
  388.       end
  389.       def to_time_zone_select_tag(priority_zones, options, html_options)
  390.         html_options = html_options.stringify_keys
  391.         add_default_name_and_id(html_options)
  392.         value = value(object)
  393.         content_tag("select",
  394.           add_options(
  395.             time_zone_options_for_select(value || options[:default], priority_zones, options[:model] || ActiveSupport::TimeZone),
  396.             options, value
  397.           ), html_options
  398.         )
  399.       end
  400.       private
  401.         def add_options(option_tags, options, value = nil)
  402.           if options[:include_blank]
  403.             option_tags = "<option value="">#{options[:include_blank] if options[:include_blank].kind_of?(String)}</option>n" + option_tags
  404.           end
  405.           if value.blank? && options[:prompt]
  406.             ("<option value="">#{options[:prompt].kind_of?(String) ? options[:prompt] : 'Please select'}</option>n") + option_tags
  407.           else
  408.             option_tags
  409.           end
  410.         end
  411.     end
  412.     class FormBuilder
  413.       def select(method, choices, options = {}, html_options = {})
  414.         @template.select(@object_name, method, choices, options.merge(:object => @object), html_options)
  415.       end
  416.       def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
  417.         @template.collection_select(@object_name, method, collection, value_method, text_method, options.merge(:object => @object), html_options)
  418.       end
  419.       def country_select(method, priority_countries = nil, options = {}, html_options = {})
  420.         @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
  421.       end
  422.       def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
  423.         @template.time_zone_select(@object_name, method, priority_zones, options.merge(:object => @object), html_options)
  424.       end
  425.     end
  426.   end
  427. end