rails/rails — pull request #7415 by schneems (2012-08-22 05:28:53+00:00)
Title: Raise error if improperly configured host in default_url_options

If the host in default_url_options is accidentally set with a protocol such as `:host => "http://example.com"` then the generated url will have the protocol twice `http://http://example.com` which is not what the user intended. Likely they wanted to define a host `:host => "example.com"` and a `:protocol => "http://"` but did not know the convention, or mistakenly added the protocol.

This is may not the most common problem, but when it happens it can go undetected for a while. I accidentally added `http://` out of habit recently only to find all the links in my emails were broken after deploying a demo site to production. Rather than allow this accident go undetected, we can stop the application from loading, and give the user a helpful error message:

Attempted to set protocol in :host of default_url_options, use {:protocol => 'http://', :host => 'example.com'} instead (RuntimeError)

This way the user is alerted that there is a problem, they must fix their host, and if the desired intent was to set declare a protocol they are told how to do that. I was able to find this related question on stack overflow: http://stackoverflow.com/questions/5878329/rails-3-devise-how-do-i-make-the-email-confirmation-links-use-secure-https-n
where the answer was highly upvoted.

If we provide a stricter contract on default_url_options (by checking for illformed options) we can provide a better developer experience to new and experienced devs.

ATP Action Mailer, Actionpack, and Railties