3

我使用 Amazon S3 进行文件上传,使用 Cloudfront 提供静态资产,在我的 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_tagsrc属性为空?即没有图像显示。我无法识别此设置有什么问题,请帮忙。

4

1 回答 1

10

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

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的协议,即'HTTP'

于 2014-05-02T10:56:52.310 回答