How can I change Rails view code for site visitors using SSL?
Posted
by pjmorse
on Stack Overflow
See other posts from Stack Overflow
or by pjmorse
Published on 2010-03-31T15:05:34Z
Indexed on
2010/03/31
15:23 UTC
Read the original article
Hit count: 295
My Rails app has some pages which are SSL-required and others which are SSL-optional. The optional pages use some assets which are served off-site (images from a vendor) which have both http and https URLs. I need to use https when the page is accessed via SSL to avoid the dreaded "this page contains both secure and insecure elements" warning.
I've written code to return the image URLs as http by default and https if requested. My problem now is determining in the view how the request came in. request.ssl? doesn't work in views.
I've tried using a before_filter which sets something like @ssl_request using request.ssl?, but that also always returns false. Is there a more elegant way to do this?
The server stack is Nginx and Passenger. Other apps with Apache => Mongrel stacks pass an X_FORWARDED_PROTO header to tell Rails that SSL is or isn't being used; is it possible that Nginx/Passenger doesn't do this?
© Stack Overflow or respective owner