From f506c8063b3084f54aa8bd157d94f10b7aed2bf0 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 1 Feb 2012 19:16:58 -0200 Subject: Add changelog, docs and guides entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Carlos Antonio da Silva + Rafael Mendonça França] --- .../lib/action_view/helpers/form_options_helper.rb | 80 +++++++++++++++++----- 1 file changed, 63 insertions(+), 17 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index cb94c8ca8a..f3e8de9ce1 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -164,7 +164,9 @@ module ActionView # # The :value_method and :text_method parameters are methods to be called on each member # of +collection+. The return values are used as the +value+ attribute and contents of each - # tag, respectively. + # tag, respectively. They can also be any object that responds to +call+, such + # as a +proc+, that will be called for each member of the +collection+ to + # retrieve the value/text. # # Example object structure for use with this method: # class Post < ActiveRecord::Base @@ -520,13 +522,17 @@ module ActionView zone_options.html_safe end - # Returns radio button tags for the collection of existing return values of +method+ for - # +object+'s class. The value returned from calling +method+ on the instance +object+ will - # be selected. If calling +method+ returns +nil+, no selection is made. + # Returns radio button tags for the collection of existing return values + # of +method+ for +object+'s class. The value returned from calling + # +method+ on the instance +object+ will be selected. If calling +method+ + # returns +nil+, no selection is made. # - # The :value_method and :text_method parameters are methods to be called on each member - # of +collection+. The return values are used as the +value+ attribute and contents of each - # radio button tag, respectively. + # The :value_method and :text_method parameters are + # methods to be called on each member of +collection+. The return values + # are used as the +value+ attribute and contents of each radio button tag, + # respectively. They can also be any object that responds to +call+, such + # as a +proc+, that will be called for each member of the +collection+ to + # retrieve the value/text. # # Example object structure for use with this method: # class Post < ActiveRecord::Base @@ -549,24 +555,46 @@ module ActionView # # # + # + # It is also possible to customize the way the elements will be shown by + # giving a block to the method: + # collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b| + # b.label { b.radio_button } + # end + # + # The argument passed to the block is a special kind of builder for this + # collection, which has the ability to generate the label and radio button + # for the current item in the collection, with proper text and value. + # Using it, you can change the label and radio button display order or + # even use the label as wrapper, as in the example above. + # + # The builder methods label and radio_button also accept + # extra html options: + # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| + # b.label(:class => "radio_button") { b.radio_button(:class => "radio_button") } + # end def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block) Tags::CollectionRadioButtons.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block) end - # Returns check box tags for the collection of existing return values of +method+ # for - # +object+'s class. The value returned from calling +method+ on the instance +object+ will - # be selected. If calling +method+ returns +nil+, no selection is made. + # Returns check box tags for the collection of existing return values of + # +method+ for +object+'s class. The value returned from calling +method+ + # on the instance +object+ will be selected. If calling +method+ returns + # +nil+, no selection is made. # - # The :value_method and :text_method parameters are methods to be called on each member - # of +collection+. The return values are used as the +value+ attribute and contents of each - # check box tag, respectively. + # The :value_method and :text_method parameters are + # methods to be called on each member of +collection+. The return values + # are used as the +value+ attribute and contents of each check box tag, + # respectively. They can also be any object that responds to +call+, such + # as a +proc+, that will be called for each member of the +collection+ to + # retrieve the value/text. # # Example object structure for use with this method: # class Post < ActiveRecord::Base - # has_and_belongs_to :author + # has_and_belongs_to_many :author # end # class Author < ActiveRecord::Base - # has_and_belongs_to :posts + # has_and_belongs_to_many :posts # def name_with_initial # "#{first_name.first}. #{last_name}" # end @@ -578,11 +606,29 @@ module ActionView # If @post.author_ids is already [1], this would return: # # - # - # + # + # # # # + # + # It is also possible to customize the way the elements will be shown by + # giving a block to the method: + # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| + # b.label { b.check_box } + # end + # + # The argument passed to the block is a special kind of builder for this + # collection, which has the ability to generate the label and check box + # for the current item in the collection, with proper text and value. + # Using it, you can change the label and check box display order or even + # use the label as wrapper, as in the example above. + # + # The builder methods label and check_box also accept + # extra html options: + # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| + # b.label(:class => "check_box") { b.check_box(:class => "check_box") } + # end def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block) Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block) end -- cgit v1.2.3