问题描述
我正在使用在应用程序,该应用程序又由 backbone.js
客户端应用程序使用。我注意到,当没有默认图像可用时,它将返回 /assets/default.png
。反过来,它必须是 http:// dev-server:3000 / assets / default.png
。这是我的配置设置:
I am using CarrierWave for image uploads on a rails-api application which in turn is consumed by a backbone.js
client app. I notice that when there is no default image available it returns /assets/default.png
. It in turn has to be http://dev-server:3000/assets/default.png
. Here are my configuration settings:
# config/environments/development.rb
CarrierWave.configure do |config|
config.asset_host = "http://dev-server:3000"
end
# Image Uploader
....
def default_url
"/assets/default.png"
end
其中我会错吗?
推荐答案
更新我在rails config中设置 asset_host
的答案。
Updating my answer to setup asset_host
in rails config.
Rails.application.configure do
.
.
config.asset_host = 'http://dev-server:3000'
end
然后,您可以使用助手的 asset_url
方法或 image_url
方法。由于这是一张图片,我建议将图片放在 app / assets / images
文件夹中,并使用 image_url
。
Then you can use asset_url
method or image_url
method of the helper. Since this is an image, I would recommend placing the image in app/assets/images
folder and use image_url
.
ActionController::Base.helpers.image_url("default.png")
这将为您提供以下URL:
This will give you the following URL:
http://dev-server:3000/images/default.png
您可以在控制台中尝试。
You can try it in the console.
[旧答案]
查看,看来您的 default_url
方法应如下所示(Carrierwave不会自动将asset_host附加到默认网址):
Looking at Carrierwave Documentation, it seems like your default_url
method should look like this (Carrierwave does not automatically perpend asset_host to the default url):
def default_url
ActionController::Base.helpers.asset_path("default.png")
end
我假设在您的Rails配置中正确设置asset_host
上。如果没有,请这样做。
I am assuming that asset_host
is setup properly in your Rails configuration. If not, please do so.
这篇关于默认图像的CarrierWave完整URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!