SSL redirects to the wrong route #10305

rickyc opened this Issue Apr 22, 2013 · 3 comments


None yet

3 participants

rickyc commented Apr 22, 2013

I've made a sample application to demonstrate this bug.

Going to redirects to

It seems that Rails redirects to the first route with matching params, controller + action name.

  match ':foo/preview/:id'                    => 'application#test',  via: [:get], as: :preview
  match ':foo/:id'                            => 'application#test',  via: [:get], as: :test

Can you link to the code? having it on Heroku is awesome, too, but having access to the code means we can confirm any fix.

rickyc commented Apr 23, 2013

Here's the commit showing the changes I made to a brand new rails app.



What's happening is that the force_ssl redirects based upon a hash passed to url_for and both routes will match the same params so the first one wins. This isn't easy to fix without Journey remembering the recognised route name and using it when it generates the url. The other option is to manipulate the url string directly rather than trying to regenerate the url.

@pixeltrix pixeltrix was assigned Apr 25, 2013
@pixeltrix pixeltrix added a commit that closed this issue Apr 25, 2013
@pixeltrix pixeltrix Use `request.fullpath` to build redirect url in `force_ssl`
The `force_ssl` command now builds the redirect url from `request.fullpath`.
This ensures that the format is maintained and it doesn't redirect to a route
that has the same parameters but is defined earlier in `routes.rb`. Also any
optional segments are maintained.

Fixes #7528.
Fixes #9061.
Fixes #10305.
@pixeltrix pixeltrix closed this in 8227bf7 Apr 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment