【问题标题】:Rails Use CDN in Development ONLY For ImagesRails 在开发中使用 CDN 仅用于图像
【发布时间】:2013-12-11 19:52:12
【问题描述】:

我正在尝试配置我的 Rails 应用程序以在 开发 中从 CDN 加载图像(我已经知道如何在生产中执行此操作)。我尝试过使用资产管道,并找到了一种方法来引用与生产环境相同结构的外部图像。唯一需要注意的是,我正在开发的所有资产现在都具有“图像”前缀,而我只想调整图像的前缀。

这可能吗?有没有更好的方法来做到这一点?

#config/environments/development.rb:

config.assets.prefix = "/images"

config.action_controller.asset_host = Proc.new do |source|
  case source
  when /\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.svg/
    "https://mycdn.com/"
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby asset-pipeline cdn


    【解决方案1】:

    prefix 移动到asset_host

    #config/environments/development.rb:
    
    config.action_controller.asset_host = Proc.new do |source|
      case source
      when /\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.svg/
        "https://mycdn.com/images"
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2011-12-29
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 2018-02-18
      • 2015-07-26
      相关资源
      最近更新 更多