gpt4 book ai didi

ruby-on-rails-4 - 如何在 Rails 4 中指定asset_host?

转载 作者:行者123 更新时间:2023-12-04 06:55:31 25 4
gpt4 key购买 nike

我使用 Amazon S3 进行文件上传,使用 Cloudfront 提供静态 Assets ,在我的 config/environments/staging.rb 中,我写道

ActionController::Base.asset_host = Proc.new { |source|
if source.include?('/assets')
"d1xw0c7m8has5k.cloudfront.net"
else
"#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
end
}

ActionMailer::Base.asset_host = Proc.new { |source|
if source.include?('/assets')
"d1xw0c7m8has5k.cloudfront.net"
else
"#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
end
}

但是在我通过 Rails 应用程序发送的邮件中,我看到 image_tag src 属性为空?即不显示图像。我无法识别此设置有什么问题,请帮忙。

最佳答案

我通过将这些配置放在 config/environments/staging.rb 的 block 中来解决这个问题

Demo::Application.configure do
config.action_controller.asset_host = Proc.new { |source|
if source.include?('/assets')
"d1xw0c7m8has5k.cloudfront.net"
else
"#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
end
}

config.action_mailer.asset_host = Proc.new { |source|
if source.include?('/assets')
"http://d1xw0c7m8has5k.cloudfront.net"
else
"http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
end
}

end

并且需要提供带有action_mailerasset_host的协议(protocol),即'HTTP'

关于ruby-on-rails-4 - 如何在 Rails 4 中指定asset_host?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23422522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com