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

Changeset 6960

Show
Ignore:
Timestamp:
06/07/07 21:35:01 (1 year ago)
Author:
bitsweat
Message:

More nested polymorphic url helper fixes. Closes #6432, references #8601.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6951 r6960  
    11*SVN* 
    22 
    3 * Resources: url_for([parent, child]) generates /parents/1/children/2 for the nested resource. Likewise with the other simply helpful methods like form_for and link_to.  #6432 [mhw, Jonathan Vaught
     3* Resources: url_for([parent, child]) generates /parents/1/children/2 for the nested resource. Likewise with the other simply helpful methods like form_for and link_to.  #6432 [mhw, Jonathan Vaught, lotswholetime
    44 
    55* Assume html format when rendering partials in RJS. #8076 [Rick] 
  • trunk/actionpack/lib/action_controller/polymorphic_routes.rb

    r6951 r6960  
    44      record = extract_record(record_or_hash_or_array) 
    55 
    6       args = [] 
     6      args = case record_or_hash_or_array 
     7        when Hash: [record_or_hash_or_array[:id]] 
     8        when Array: record_or_hash_or_array.dup 
     9        else [record_or_hash_or_array] 
     10        end 
     11 
     12      args.pop # Remove the base record; we only need it in one case 
     13 
    714      inflection = 
    815        case 
     
    1219          :plural 
    1320        else 
    14           args = [record_or_hash_or_array] 
     21          args.push(record) # Put the base record back in 
    1522          :singular 
    1623        end 
    17  
     24       
    1825      named_route = build_named_route_call(record_or_hash_or_array, inflection, options) 
    1926      send(named_route, *args) 
  • trunk/actionpack/lib/action_view/helpers/form_helper.rb

    r6959 r6960  
    167167          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_or_array) 
    170169          apply_form_for_options!(record_or_name_or_array, options) 
    171170          args.unshift object 
     
    173172          object = record_or_name_or_array 
    174173          object_name = ActionController::RecordIdentifier.singular_class_name(object) 
    175           apply_form_for_options!([ object ], options) 
     174          apply_form_for_options!([object], options) 
    176175          args.unshift object 
    177176        end 
  • trunk/actionpack/test/template/form_helper_test.rb

    r6959 r6960  
    3939  include ActionView::Helpers::ActiveRecordHelper 
    4040  include ActionView::Helpers::RecordIdentificationHelper 
     41  include ActionController::PolymorphicRoutes 
    4142 
    4243  def setup 
     
    637638      "/posts/#{post.id}/comments" 
    638639    end 
     640    alias_method :post_comments_path, :comments_path 
    639641 
    640642    def comment_path(post, comment) 
    641643      "/posts/#{post.id}/comments/#{comment.id}" 
    642644    end 
    643  
    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? 
    661           "/posts" 
    662         else 
    663           "/posts/#{record.id}" 
    664         end           
    665       end         
     645    alias_method :post_comment_path, :comment_path 
     646     
     647    def posts_path 
     648      "/posts" 
     649    end  
     650     
     651    def post_path(post) 
     652      "/posts/#{post.id}" 
    666653    end 
    667654end