Skip to content

Commit

Permalink
Revert "Refactor passing url options via array for polymorphic_url"
Browse files Browse the repository at this point in the history
Passing options as the last value in an array doesn't work with form_for.
This reverts commit 6be564c.
  • Loading branch information
pixeltrix committed Aug 4, 2012
1 parent 96290d4 commit 4059423
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 11 deletions.
2 changes: 0 additions & 2 deletions actionpack/CHANGELOG.md
@@ -1,7 +1,5 @@
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##


* Add the ability to pass options as part of the array notation for `polymorphic_url` *Romain Tribes*

* Fixed issue with where Digest authentication would not work behind a proxy. *Arthur Smith* * Fixed issue with where Digest authentication would not work behind a proxy. *Arthur Smith*


* Added ActionController::Live. Mix it in to your controller and you can * Added ActionController::Live. Mix it in to your controller and you can
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
Expand Up @@ -93,7 +93,6 @@ module PolymorphicRoutes
def polymorphic_url(record_or_hash_or_array, options = {}) def polymorphic_url(record_or_hash_or_array, options = {})
if record_or_hash_or_array.kind_of?(Array) if record_or_hash_or_array.kind_of?(Array)
record_or_hash_or_array = record_or_hash_or_array.compact record_or_hash_or_array = record_or_hash_or_array.compact
options.reverse_merge!(record_or_hash_or_array.extract_options!)
if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy) if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy)
proxy = record_or_hash_or_array.shift proxy = record_or_hash_or_array.shift
end end
Expand Down Expand Up @@ -166,6 +165,7 @@ def routing_type(options)


def build_named_route_call(records, inflection, options = {}) def build_named_route_call(records, inflection, options = {})
if records.is_a?(Array) if records.is_a?(Array)
query_string = records.pop if records.last.is_a?(Hash)
record = records.pop record = records.pop
route = records.map do |parent| route = records.map do |parent|
if parent.is_a?(Symbol) || parent.is_a?(String) if parent.is_a?(Symbol) || parent.is_a?(String)
Expand Down Expand Up @@ -199,7 +199,7 @@ def build_named_route_call(records, inflection, options = {})
def extract_record(record_or_hash_or_array) def extract_record(record_or_hash_or_array)
case record_or_hash_or_array case record_or_hash_or_array
when Array when Array
record_or_hash_or_array.last record_or_hash_or_array.last.is_a?(Hash) ? record_or_hash_or_array[-2] : record_or_hash_or_array.last
when Hash; record_or_hash_or_array[:id] when Hash; record_or_hash_or_array[:id]
else record_or_hash_or_array else record_or_hash_or_array
end end
Expand Down
7 changes: 0 additions & 7 deletions actionpack/test/activerecord/polymorphic_routes_test.rb
Expand Up @@ -323,13 +323,6 @@ def test_with_array_containing_complex_hash
end end
end end


def test_with_array_containing_simple_hash_options_take_precedence
with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}?foo=baz", polymorphic_url([@project, :foo => 'bar' ], :foo => 'baz')
end
end

def test_with_array_containing_single_name def test_with_array_containing_single_name
with_test_routes do with_test_routes do
@project.save @project.save
Expand Down

0 comments on commit 4059423

Please sign in to comment.