I am trying to add dynamic cloudfront asset full paths into my scss. The path changes based on the evironment (staging, etc)
mystyle.scss
.some-image {background-image: url(asset_path("#{Rails.configuration.adjusted_s3_cloudfront_path}landing/this-image.jpg"))}
.some-image {background-image: url(Rails.configuration.adjusted_s3_cloudfront_path('/landing/this-image.jpg'))}
.some-image {background-image: url(<% Rails.configuration.adjusted_s3_cloudfront_path %>"/landing/this-image.jpg")}
config.adjusted_s3_cloudfront_path = "https://somecloufrontnumber.cloudfront.net"
config.adjusted_s3_cloudfront_path = "https://#{ENV['S3_CLOUDFRONT_URL']}"
Why don't you remove config.adjusted_s3_cloudfront_path = "https://#{ENV['S3_CLOUDFRONT_URL']}"
in favor of declaring a helper in app/controllers/application.rb
?
.some-image {
background-image: url(<%= cloudfront_path('landing/this-image.jpg') %>)
}
app/controller/application.rb
class ApplicationController < ActionController::Base
def cloudfront_path(asset_uri)
return ENV['S3_CLOUDFRONT_URL'] + 'asset_url'
end
end