Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6959

Show
Ignore:
Timestamp:
06/06/07 16:52:37 (3 years ago)
Author:
bitsweat
Message:

Fix incomplete work from [6951] that was hidden by test stubs. Closes #6432.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_view/helpers/form_helper.rb

    r6951 r6959  
    156156      # 
    157157      # If you don't need to attach a form to a model instance, then check out FormTagHelper#form_tag. 
    158       def form_for(record_or_name, *args, &proc) 
     158      def form_for(record_or_name_or_array, *args, &proc) 
    159159        raise ArgumentError, "Missing block" unless block_given? 
    160160 
    161161        options = args.last.is_a?(Hash) ? args.pop : {} 
    162162 
    163         case record_or_name 
     163        case record_or_name_or_array 
    164164        when String, Symbol 
    165           object_name = record_or_name 
     165          object_name = record_or_name_or_array 
    166166        when Array 
    167           object = record_or_name.last 
     167          object = record_or_name_or_array.last 
    168168          object_name = ActionController::RecordIdentifier.singular_class_name(object) 
    169           apply_form_for_options!(object, options, *record_or_name) 
     169          # apply_form_for_options!(object, options, *record_or_name_or_array) 
     170          apply_form_for_options!(record_or_name_or_array, options) 
    170171          args.unshift object 
    171172        else 
    172           object = record_or_name 
     173          object = record_or_name_or_array 
    173174          object_name = ActionController::RecordIdentifier.singular_class_name(object) 
    174           apply_form_for_options!(object, options) 
     175          apply_form_for_options!([ object ], options) 
    175176          args.unshift object 
    176177        end 
     
    181182      end 
    182183 
    183       def apply_form_for_options!(object, options, *nested_objects) #:nodoc: 
     184      def apply_form_for_options!(object_or_array, options) #:nodoc: 
     185        object = object_or_array.is_a?(Array) ? object_or_array.last : object_or_array 
     186         
    184187        html_options = 
    185188          if object.respond_to?(:new_record?) && object.new_record? 
     
    191194        options[:html] ||= {} 
    192195        options[:html].reverse_merge!(html_options) 
    193         options[:url] ||= polymorphic_path(object, *nested_objects
     196        options[:url] ||= polymorphic_path(object_or_array
    194197      end 
    195198 
  • trunk/actionpack/test/template/form_helper_test.rb

    r6951 r6959  
    642642    end 
    643643 
    644     def polymorphic_path(object, *nested_objects) 
    645       if nested_objects.empty? 
    646         if object.new_record? 
     644    def polymorphic_path(record_or_hash_or_array)   
     645      if record_or_hash_or_array.is_a?(Array) 
     646        record = record_or_hash_or_array.pop 
     647        array = record_or_hash_or_array 
     648      else 
     649        record = record_or_hash_or_array 
     650        array = [ ] 
     651      end 
     652       
     653      if array.size > 0 
     654        if record.new_record?  
     655          "/posts/123/comments" 
     656        else 
     657          "/posts/123/comments/#{record.id}" 
     658        end 
     659      else 
     660        if record.new_record? 
    647661          "/posts" 
    648662        else 
    649           "/posts/#{object.id}" 
    650         end 
    651       else 
    652         if object.new_record? 
    653           "/posts/123/comments" 
    654         else 
    655           "/posts/123/comments/#{object.id}" 
    656         end 
    657       end 
     663          "/posts/#{record.id}" 
     664        end           
     665      end         
    658666    end 
    659667end