Changeset 1031
- Timestamp:
- 11/22/07 05:33:13 (11 months ago)
- Files:
-
- plugins/merb_helpers/lib/form_helpers.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/merb_helpers/lib/form_helpers.rb
r1028 r1031 355 355 :value_method => attrs.delete(:value_method) 356 356 } 357 optional_label(attrs) { open_tag('select', attrs) + options_f or_select(collection, option_attrs) + "</select>"}357 optional_label(attrs) { open_tag('select', attrs) + options_from_collection_for_select(collection, option_attrs) + "</select>"} 358 358 end 359 359 … … 434 434 # +selected+:: The value of a selected object, may be either a string or an array. 435 435 def options_from_collection_for_select(collection, attrs = {}) 436 if collection.is_a?(Hash) 437 returning '' do |ret| 438 collection.each do |label, group| 439 ret << open_tag("optgroup", :label => label.to_s) + options_from_collection_for_select(group, attrs) + "</optgroup>" 440 end 436 prompt = attrs.delete(:prompt) 437 blank = attrs.delete(:include_blank) 438 if collection.is_a?(Hash) 439 returning '' do |ret| 440 ret << tag("option", prompt, :value => '') if prompt 441 ret << tag("option", '', :value => '') if blank 442 collection.each do |label, group| 443 ret << open_tag("optgroup", :label => label.to_s) + options_from_collection_for_select(group, attrs) + "</optgroup>" 441 444 end 442 else443 text_method = attrs[:text_method]444 value_method = attrs[:value_method]445 selected_value = attrs[:selected]446 options_for_select(447 collection.inject([]) { |options, object| options << [ object.send(value_method), object.send(text_method) ] },448 :selected => selected_value449 )450 445 end 446 else 447 text_method = attrs[:text_method] 448 value_method = attrs[:value_method] 449 selected_value = attrs[:selected] 450 options_for_select( 451 collection.inject([]) { |options, object| options << [ object.send(value_method), object.send(text_method) ] }, 452 :selected => selected_value, :include_blank => blank, :prompt => prompt 453 ) 454 end 451 455 end 452 456
