Ruby Question

How to use PaperClip to retrieve an image over HTTPS using RoR?

I have an application which stores and retrieves images from Amazons

AWS
.

In order to do that I'm using paperclip.

I use an SSL certification for my application and so require all calls to use HTTPS.

In order to get an image from Amazon
AWS
I do the following:

<div class="col-md-6 col-md-offset-3 shopHeader">
<img class="img-responsive center-block" widith="150px" height="100px" src=<%= @shop.image.url(:original, timestamp:false) %>>
</div>


And when the page loads calls an URL such as http://cardapiopsbrasil.s3.amazonaws.com/original/shop/221

Instead I need to use HTTPS by generating a link such as https://cardapiopsbrasil.s3.amazonaws.com/original/shop/221

However I'm receiving some warnings such as:

Mixed Content: The page at 'https://cardapioalfenas.com.br/' was loaded over HTTPS, but requested an insecure image 'http://cardapiopsbrasil.s3.amazonaws.com/original/shop/221'. This content should also be served over HTTPS.


Is there any way to tell Paperclip or my application to use HTTPS calls to get these images?

Answer

theres an option for has_attached_file in your model that specifies the protocol to use

# app/models/shop.rb
has_attached_file :image,
                  storage: :s3,
                  s3_protocol: :https #specify the protocol as https

the documentation explains the various options