【问题标题】:how to specify asset_host in rails 4?如何在 Rails 4 中指定asset_host?
【发布时间】:2014-06-18 19:21:10
【问题描述】:

我使用 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_tag src 属性为空? 即不显示图像。 我无法识别此设置有什么问题,请帮忙。

【问题讨论】:

    标签: ruby-on-rails-4 amazon-s3 actionmailer amazon-cloudfront ruby-2.1


    【解决方案1】:

    我通过将这些配置放在 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'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多