仅对Rails 3.1中的图像使用asset_host proc

TTD*_*eTT 5 ruby-on-rails ruby-on-rails-3.1 asset-pipeline

在以前版本的rails中,我能够使用proc仅为来自其他服务器的图像资源提供:

ActionController::Base.asset_host = Proc.new { |source|
  if source.starts_with?('/images')
   "https://s3.amazonaws.com/..."
  end
}
Run Code Online (Sandbox Code Playgroud)

由于新的资产管道,这在Rails 3.1中似乎不起作用.任何人都知道如何使这个工作?

Ten*_*ack 7

这似乎有点像黑客,但它的工作原理:

  config.action_controller.asset_host = Proc.new { |source|
    if source =~ /\b(.png|.jpg|.gif)\b/i
      "https://s3.amazonaws.com/bucketName"
    end
  }
Run Code Online (Sandbox Code Playgroud)

该文件夹需要在此存储桶中调用资产而不是图像.