I am using carrierwave to upload images to s3. And that is working fine and dandy. However the default_url is not.
In my uploader I have the default_url set to use the rails asset pipeline.
def default_url
ActionController::Base.helpers.asset_path("panOpen_v2/" + [version_name, "panopen_beta_logo_flat_white_med.png"].compact.join('_'))
end
So that sort of works fine.
src="/assets/panOpen_v2/panopen_beta_logo_flat_white_med-1ed9964153466e88fe64c422dbab98ca.png"
It creates the link to the image but it still links to my server instead of my CDN. All of the rest of my assets link to my CDN just fine, so I know rails is setup just fine with my CDN.
Does anyone have any ideas?
I thought about prepending the cdn url in there for prod and staging env, but I shouldn't have to do that. Perhaps that is the only way though?
I fixed it using what I had thought about doing. And that is prepending the CDN url during prod and staging env.
def default_url
if !(Rails.env.development? || Rails.env.test?)
"#{Settings.asset_host}#{ActionController::Base.helpers.asset_path("panOpen_v2/" + [version_name, "panopen_beta_logo_flat_white_med.png"].compact.join('_'))}"
else
ActionController::Base.helpers.asset_path("panOpen_v2/" + [version_name, "panopen_beta_logo_flat_white_med.png"].compact.join('_'))
end
end
The Settings.asset_host
is the url to my CDN.
It's not a perfect solution. And I'd rather not have to do that. So if anyone has a better idea, I'd love to hear it.