开发者

Using asset_host proc for only images in Rails 3.1

开发者 https://www.devze.com 2023-03-27 19:19 出处:网络
In previous versions of rails I was able to use a proc to serve only image assets from another server with:

In previous versions of rails I was able to use a proc to serve only image assets from another server with:

ActionController::Base.asset_host = Proc.new { |source|
  if source.starts_with?('/images')
   "https://s3.amazonaws.com/.开发者_高级运维.."
  end
}

This doesn't seem to work in Rails 3.1 due to the new asset pipeline. Anyone know how to get this working?


This seems like kinda a hack but it works:

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

The folder needs to be called assets inside this bucket and not images.

0

精彩评论

暂无评论...
验证码 换一张
取 消