title: Handling mix of HTTP and HTTPS links on a page
body: <p>My setup: Rails 3.0.9, Ruby 1.9.2</p>
  
  <p>My app requires that only a certain part of my site be SSL protected and the rest not. In case anyone thinks this isn't normal behavior, check out Amazon. When merely browsing for products, it's in HTTP mode, during checkout, it switches to HTTPS. Even in the middle of a secure checkout transaction, there are several other links on the same page that are HTTP only.</p>
  
  <p>I looked at ssl_requirement gem and decided not to use it because it isn't a complete solution for my needs. I ended up setting up specific SSL routes like</p>
  
  <pre><code>resources :projects do
      resources :tasks, :constraints =&gt; { :protocol =&gt; "https" }
  end
  </code></pre>
  
  <p>In my view code, for HTTP specific links</p>
  
  <pre><code>&lt;%= link_to 'Projects', project_url(@project, :protocol =&gt; "http") %&gt;
  </code></pre>
  
  <p>and to handle HTTPS specific link</p>
  
  <pre><code>&lt;%= link_to 'Task', new_project_task_url(@project, :protocol =&gt; "https") %&gt;
  </code></pre>
  
  <p>I understand this isn't the cleanest way but it's what I have decided to do. The problem with this setup is how to properly set both HTTP and HTTPS links on every page. There is a proposed solution <a href="https://stackoverflow.com/questions/3993651/rails-3-ssl-routing-redirects-from-https-to-http">here</a> but it requires wholesale changes _path to _url and I prefer to avoid that if at all possible. The solutions involves adding this method in </p>
  
  <pre><code>application_helper.rb
  
  module ApplicationHelper
    def url_for(options = nil)
      if Hash === options
        options[:protocol] ||= 'http'
      end
      super(options)
    end
  end
  </code></pre>
  
  <p>So my question is it possible to change this method or another one to change _path calls to explicit urls so I can use the above method to set the proper protocol.</p>