From c3f53f412cd170fc295b46e48aa81837ad15ec83 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 19 Dec 2008 14:27:43 +0000 Subject: Merge docrails --- actionpack/lib/action_view/helpers/date_helper.rb | 2 +- .../lib/action_view/helpers/form_options_helper.rb | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 22108dd99d..a04bb8c598 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -111,7 +111,7 @@ module ActionView # # ==== Options # * :use_month_numbers - Set to true if you want to use month numbers rather than month names (e.g. - # "2" instead of "February"). + # "2" instead of "February"). # * :use_short_month - Set to true if you want to use the abbreviated month name instead of the full # name (e.g. "Feb" instead of "February"). # * :add_month_number - Set to true if you want to show both, the month's number and name (e.g. diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 33f8aaf9ed..9ed50a9653 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -201,13 +201,21 @@ module ActionView # Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the # the result of a call to the +value_method+ as the option value and the +text_method+ as the option text. - # If +selected+ is specified, the element returning a match on +value_method+ will get the selected option tag. + # Example: + # options_from_collection_for_select(@people, 'id', 'name') + # This will output the same HTML as if you did this: + # # - # Example (call, result). Imagine a loop iterating over each +person+ in @project.people to generate an input tag: - # options_from_collection_for_select(@project.people, "id", "name") - # + # This is more often than not used inside a #select_tag like this example: + # select_tag 'person', options_from_collection_for_select(@people, 'id', 'name') # - # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. + # If +selected+ is specified, the element returning a match on +value_method+ will get the selected option tag. + # Be sure to specify the same class as the +value_method+ when specifying a selected option. + # Failure to do this will produce undesired results. Example: + # options_from_collection_for_select(@people, 'id', 'name', '1') + # Will not select a person with the id of 1 because 1 (an Integer) is not the same as '1' (a string) + # options_from_collection_for_select(@people, 'id', 'name', 1) + # should produce the desired results. def options_from_collection_for_select(collection, value_method, text_method, selected = nil) options = collection.map do |element| [element.send(text_method), element.send(value_method)] -- cgit v1.2.3