title: Getting Rails URL helpers to automatically output https urls
body: <p>I am developing a site that mixes http and https a lot - whats the best/easiest way to make the links use the right protocol for the route - can it be specified in the routes file?</p>
  
  <p>Say I have the following route in Rails 3.</p>
  
  <pre>match "/test" => "test#index", :as => :test, :constraints => { :protocol => 'https' }</pre>
  
  <p>If I'm on a http page, and I use <code>test_url()</code>, it'll output <a href="http://domain.com/test" rel="noreferrer">http://domain.com/test</a>.  I want <a href="https://domain.com/test" rel="noreferrer">https://domain.com/test</a> instead.</p>
  
  <p>I know I can use <code>test_url(:secure => true)</code>, but that's duplicating logic.  </p>
  
  <p>I know I could have <a href="http://domain.com/test" rel="noreferrer">http://domain.com/test</a> to <a href="https://domain.com/test" rel="noreferrer">https://domain.com/test</a>, but that's an extra redirect, plus it fails on form posts.</p>
  
  <p>Ideas?</p>