Changeset 6751
- Timestamp:
- 05/18/07 00:36:14 (1 year ago)
- Files:
-
- trunk/actionpack/lib/action_controller/base.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/polymorphic_routes.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/helpers/form_helper.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_view/helpers/prototype_helper.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/url_helper.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/partials.rb (modified) (1 diff)
- trunk/actionpack/test/template/form_helper_test.rb (modified) (1 diff)
- trunk/actionpack/test/template/prototype_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/base.rb
r6750 r6751 561 561 @url.rewrite(rewrite_options(options)) 562 562 else 563 polymorphic_url(options , self)563 polymorphic_url(options) 564 564 end 565 565 end … … 1035 1035 else 1036 1036 redirect_to(url_for(options)) 1037 response.redirected_to = options1038 1037 end 1039 1038 end trunk/actionpack/lib/action_controller/polymorphic_routes.rb
r6731 r6751 1 1 module ActionController 2 2 module PolymorphicRoutes 3 extend self 4 5 def polymorphic_url(record_or_hash, url_writer, options = {}) 3 def polymorphic_url(record_or_hash, options = {}) 6 4 record = extract_record(record_or_hash) 7 5 8 6 case 9 7 when options[:action] == "new" 10 url_writer.send(8 send( 11 9 action_prefix(options) + RecordIdentifier.singular_class_name(record) + routing_type(options) 12 10 ) 13 11 14 12 when record.respond_to?(:new_record?) && record.new_record? 15 url_writer.send(13 send( 16 14 action_prefix(options) + RecordIdentifier.plural_class_name(record) + routing_type(options) 17 15 ) 18 16 19 17 else 20 url_writer.send(18 send( 21 19 action_prefix(options) + RecordIdentifier.singular_class_name(record) + routing_type(options), record_or_hash 22 20 ) … … 24 22 end 25 23 26 def polymorphic_path(record_or_hash , url_writer)27 polymorphic_url(record_or_hash, url_writer,:routing_type => :path)24 def polymorphic_path(record_or_hash) 25 polymorphic_url(record_or_hash, :routing_type => :path) 28 26 end 29 27 30 28 %w( edit new formatted ).each do |action| 31 module_eval <<-EOT 32 def #{action}_polymorphic_url(record_or_hash , url_writer)33 polymorphic_url(record_or_hash, url_writer,:action => "#{action}")29 module_eval <<-EOT, __FILE__, __LINE__ 30 def #{action}_polymorphic_url(record_or_hash) 31 polymorphic_url(record_or_hash, :action => "#{action}") 34 32 end 35 33 36 def #{action}_polymorphic_path(record_or_hash , url_writer)37 polymorphic_url(record_or_hash, url_writer,:action => "#{action}", :routing_type => :path)34 def #{action}_polymorphic_path(record_or_hash) 35 polymorphic_url(record_or_hash, :action => "#{action}", :routing_type => :path) 38 36 end 39 37 EOT … … 45 43 options[:action] ? "#{options[:action]}_" : "" 46 44 end 47 45 48 46 def routing_type(options) 49 47 "_#{options[:routing_type] || "url"}" 50 48 end 51 49 52 50 def extract_record(record_or_hash) 53 51 record_or_hash.is_a?(Hash) ? record_or_hash[:id] : record_or_hash trunk/actionpack/lib/action_view/helpers/form_helper.rb
r6731 r6751 168 168 object_name = ActionController::RecordIdentifier.singular_class_name(record_or_name) 169 169 apply_form_for_options!(object, options) 170 args.unshift object 170 171 end 171 172 … … 185 186 options[:html].reverse_merge!(html_options) 186 187 187 options[:url] ||= polymorphic_path(object , self)188 options[:url] ||= polymorphic_path(object) 188 189 end 189 190 trunk/actionpack/lib/action_view/helpers/prototype_helper.rb
r6731 r6751 192 192 object_name = ActionController::RecordIdentifier.singular_class_name(record_or_name) 193 193 apply_form_for_options!(object, options) 194 args.unshift object 194 195 end 195 196 trunk/actionpack/lib/action_view/helpers/url_helper.rb
r6729 r6751 76 76 else 77 77 escape = false 78 url = polymorphic_path(options , self)78 url = polymorphic_path(options) 79 79 end 80 80 trunk/actionpack/lib/action_view/partials.rb
r6404 r6751 49 49 # Deprecated, use render :partial 50 50 def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc: 51 path, partial_name = partial_pieces(partial_path) 52 object = extracting_object(partial_name, local_assigns, deprecated_local_assigns) 53 local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns) 54 local_assigns = local_assigns ? local_assigns.clone : {} 55 add_counter_to_local_assigns!(partial_name, local_assigns) 56 add_object_to_local_assigns!(partial_name, local_assigns, object) 51 case partial_path 52 when String, Symbol, NilClass 53 path, partial_name = partial_pieces(partial_path) 54 object = extracting_object(partial_name, local_assigns, deprecated_local_assigns) 55 local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns) 56 local_assigns = local_assigns ? local_assigns.clone : {} 57 add_counter_to_local_assigns!(partial_name, local_assigns) 58 add_object_to_local_assigns!(partial_name, local_assigns, object) 57 59 58 if logger 59 ActionController::Base.benchmark("Rendered #{path}/_#{partial_name}", Logger::DEBUG, false) do 60 if logger 61 ActionController::Base.benchmark("Rendered #{path}/_#{partial_name}", Logger::DEBUG, false) do 62 render("#{path}/_#{partial_name}", local_assigns) 63 end 64 else 60 65 render("#{path}/_#{partial_name}", local_assigns) 61 66 end 67 when Array 68 if partial_path.any? 69 path = ActionController::RecordIdentifier.partial_path(partial_path.first) 70 collection = partial_path 71 render_partial_collection(path, collection, nil, local_assigns.value) 72 else 73 "" 74 end 62 75 else 63 render("#{path}/_#{partial_name}", local_assigns) 76 render_partial( 77 ActionController::RecordIdentifier.partial_path(partial_path), 78 local_assigns, deprecated_local_assigns) 64 79 end 65 80 end trunk/actionpack/test/template/form_helper_test.rb
r6731 r6751 602 602 603 603 protected 604 def polymorphic_path(record , url_writer)604 def polymorphic_path(record) 605 605 if record.new_record? 606 606 "/posts" trunk/actionpack/test/template/prototype_helper_test.rb
r6731 r6751 215 215 end 216 216 217 def polymorphic_path(record , url_writer)217 def polymorphic_path(record) 218 218 if record.new_record? 219 219 "/authors"