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?
Try a before_filter in application.rb:
before_filter { |c| UMNAuthFilter.filter(c) if c.request.ssl? }
EDITed to add correctness :)
<img src="//cdn.example.com/images/99dbe20bc52e4caa.jpg">
精彩评论