Changeset 6960
- Timestamp:
- 06/07/07 21:35:01 (1 year ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/polymorphic_routes.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_view/helpers/form_helper.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/polymorphic_routes_test.rb (added)
- trunk/actionpack/test/template/form_helper_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6951 r6960 1 1 *SVN* 2 2 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] 4 4 5 5 * Assume html format when rendering partials in RJS. #8076 [Rick] trunk/actionpack/lib/action_controller/polymorphic_routes.rb
r6951 r6960 4 4 record = extract_record(record_or_hash_or_array) 5 5 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 7 14 inflection = 8 15 case … … 12 19 :plural 13 20 else 14 args = [record_or_hash_or_array]21 args.push(record) # Put the base record back in 15 22 :singular 16 23 end 17 24 18 25 named_route = build_named_route_call(record_or_hash_or_array, inflection, options) 19 26 send(named_route, *args) trunk/actionpack/lib/action_view/helpers/form_helper.rb
r6959 r6960 167 167 object = record_or_name_or_array.last 168 168 object_name = ActionController::RecordIdentifier.singular_class_name(object) 169 # apply_form_for_options!(object, options, *record_or_name_or_array)170 169 apply_form_for_options!(record_or_name_or_array, options) 171 170 args.unshift object … … 173 172 object = record_or_name_or_array 174 173 object_name = ActionController::RecordIdentifier.singular_class_name(object) 175 apply_form_for_options!([ object], options)174 apply_form_for_options!([object], options) 176 175 args.unshift object 177 176 end trunk/actionpack/test/template/form_helper_test.rb
r6959 r6960 39 39 include ActionView::Helpers::ActiveRecordHelper 40 40 include ActionView::Helpers::RecordIdentificationHelper 41 include ActionController::PolymorphicRoutes 41 42 42 43 def setup … … 637 638 "/posts/#{post.id}/comments" 638 639 end 640 alias_method :post_comments_path, :comments_path 639 641 640 642 def comment_path(post, comment) 641 643 "/posts/#{post.id}/comments/#{comment.id}" 642 644 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}" 666 653 end 667 654 end