diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-12-19 14:27:43 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-12-19 14:27:43 +0000 |
commit | c3f53f412cd170fc295b46e48aa81837ad15ec83 (patch) | |
tree | 79de6effe9874f3d17eada3666c13b5f76fa537c /actionpack/lib/action_view | |
parent | 89b75814045e811d52b19278ae27b5f45c6d9dd6 (diff) | |
download | rails-c3f53f412cd170fc295b46e48aa81837ad15ec83.tar.gz rails-c3f53f412cd170fc295b46e48aa81837ad15ec83.tar.bz2 rails-c3f53f412cd170fc295b46e48aa81837ad15ec83.zip |
Merge docrails
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 18 |
2 files changed, 14 insertions, 6 deletions
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 # * <tt>:use_month_numbers</tt> - Set to true if you want to use month numbers rather than month names (e.g. - # "2" instead of "February"). + # "2" instead of "February"). # * <tt>:use_short_month</tt> - Set to true if you want to use the abbreviated month name instead of the full # name (e.g. "Feb" instead of "February"). # * <tt>:add_month_number</tt> - 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: + # <option value="#{person.id}">#{person.name}</option> # - # Example (call, result). Imagine a loop iterating over each +person+ in <tt>@project.people</tt> to generate an input tag: - # options_from_collection_for_select(@project.people, "id", "name") - # <option value="#{person.id}">#{person.name}</option> + # 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)] |