rails/rails — pull request #14615 by andrielfn (2014-04-06 01:31:18+00:00)
Title: url_options takes precedence over route defaults

It fixes https://github.com/rails/rails/issues/7144#issuecomment-38851902.

We are fixing two related things here: the query string parameter precedence over the route defaults parameters, and the proper url rendering with these default parameters.

Use case:

```ruby
# routes.rb
get 'test' => 'welcome#index', defaults: { foo: 'foo_default' }
```

Without the fix:

```ruby
url_for(foo: 'new_foo') # /test

# GET /test?foo=new_foo
params # {"foo"=>"foo_default", "action"=>"index", "controller"=>"welcome"}
```

With the fix:

```ruby
url_for(foo: 'new_foo') # /test?foo=new_foo

# GET /test?foo=new_foo
params # {"foo"=>"new_foo", "action"=>"index", "controller"=>"welcome"}
```

What we did was distinguish what are the route options and what are the route defaults, thus the provided attribute isn't removed from `url_options` anymore.

Many thanks to @fabioyamate for pairing with me to solve this.