Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<route>_url helpers should know if they should be using https or http #3571

Closed
joevandyk opened this issue Nov 8, 2011 · 7 comments
Closed
Assignees

Comments

@joevandyk
Copy link
Contributor

If I specify in my routes that a given URL should be using https, then using the _url route helper should output a https url.

Example:

scope :constraints => { :protocol => "https" } do
  match '/login' => 'controller#action', :as => 'login'
end

match '/' => 'welcome#index', :as => 'index'

login_url should output https://domain.com/login , even if I'm on a http page.

index_url should output http://domain.com/, even if I'm on a https page.

See http://stackoverflow.com/questions/3993651/rails-3-ssl-routing-redirects-from-https-to-http and http://stackoverflow.com/questions/6699881/getting-rails-url-helpers-to-automatically-output-https-urls for a discussion of this issue.

@sarahhodne
Copy link
Contributor

I agree with you on the login_url part, but I don't think you should change off of HTTPS automatically, as you propose for index_url. Also, one of the links you posted has a solution for how to make this work.

@joevandyk
Copy link
Contributor Author

I saw the solution in the stackoverflow ticket, but it involved overriding url_for in multiple places, which seems hacky.

Maybe if you constrain index_url to http then it would switch back to http? If there's no protocol constraints, then it doesn't touch it?

@sarahhodne
Copy link
Contributor

From what I can see, this is what the Stack Overflow ticket is suggesting:

# routes.rb
scope :protocol => 'https://', :constraints => { :protocol => 'https://' } do
  resources :sessions
end

resources :gizmos

So no url_for overriding (unless you want https -> http which I said I thought was a bad idea, I'll expand on that thought if you want me to).

@joevandyk
Copy link
Contributor Author

I can't seem to get those routes to work though, using the above routes file, when I use new_session_url in a view, I get this error:

No route matches {:action=>"new", :controller=>"sessions"}

It (of course) works when I remove the scope from around the resources :sessions.

@isaacsanders
Copy link
Contributor

@joevandyk any news in this? @tenderlove @josevalim

@joevandyk
Copy link
Contributor Author

I think it's still a problem. Would love to have it fixed.

@isaacsanders
Copy link
Contributor

Do you have time to work on a patch?

@ghost ghost assigned pixeltrix May 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants