I had roughly the same problem and in my case it was because the
proper headers weren't being set. Rails uses certain headers to
determine if the current request is using SSL and thus if it should
use https:// when generating URLs with url_for(). I had to add the
following line to my Apache configuration for the secure virtualhost
to get it to work:
RequestHeader set X_FORWARDED_PROTO 'https'
A quick glance at the ActionController source reveals this method:
# Is this an SSL request?
@env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] ==
I'm not sure why I didn't need to append "HTTP_" to the request header
name, but it works (probably because somewhere along the line it gets
Try setting any of these headers in your web server's configuration.
Best of luck.