Rails Active Storage で画像ファイルをHTTPSで配信したい
HTTPSページにて、AWS S3に保存された画像ファイルをActive Storageで配信すると、Mixed content
エラーが発生します。
ref:
https://www.mixedcontentexamples.com/Test/NonSecureImage
https://www.mixedcontentexamples.com/
デバッガーツールのSecurity
タブからも確認できます。
これはRailsのurl_helper
メソッドがデフォルトではHTTPを使うため。
config.force_ssl = true
とした上で、config/initializers/force_ssl.rb
ファイルを作成し
Rails.application.routes.default_url_options[:protocol] = 'https' if Rails.application.config.force_ssl
とすれば良さそうです
ref:
https://medium.com/@stacietaylorcima/rails-active-storage-serve-your-images-over-https-14b916c67a51