Rails 3.2 asset_host 设置被忽略 [英] Rails 3.2 asset_host setting ignored

查看:45
本文介绍了Rails 3.2 asset_host 设置被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的生产环境-

# Code is not reloaded between requests
  config.cache_classes = true
  config.assets.enabled = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = true
  config.static_cache_control = "public, max-age=31536000"

  # Compress JavaScripts and CSS
  config.assets.compress = true
  config.assets.js_compressor  = :uglifier
  #config.assets.css_compressor = :yui

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true

  # Generate digests for assets URLs
  config.assets.digest = true

  # See everything in the log (default is :info)
  config.log_level = :warn
  config.log_tags = [:remote_ip, lambda { |req| Time.now }]

  # Enable serving of images, stylesheets, and JavaScripts from an asset server
  ActionController::Base.asset_host = Proc.new { |source|
    unless source.starts_with?('/stylesheets' || '/javascripts')
      "//dddd.cloudfront.net/"
    end
   }

但是,当我使用 image_tag 时,它仍然返回/assets.."相对 url 而不是资产主机的绝对 url.

However, when I using image_tag it still returns me '/assets..' relative url and not absolute url to the asset host.

irb(main):034:0> helper.image_tag('noimage.gif')
=> "<img alt=\"Noimage\" src=\"/assets/noimage.gif\" />"
irb(main):035:0> helper.image_path('noimage.gif')

我似乎无法弄清楚可能缺少什么.我什至尝试做简单的 config.asset_host 设置,但它仍然无法识别该设置.

I can not seem to figure what might be missing. I even tried doing simple config.asset_host setting, and still it does not recognize the setting.

推荐答案

您是否尝试过设置指定的配置?

Have you tried setting the designated config?

config.action_controller.asset_host = 'https://abcd.cloudfront.net'

不确定它是否适用于协议相关网址.我只是在我的应用中使用 https.

Not sure it works with protocol relative urls. I simply use https in my apps.

值得注意的是,action mailer 也有类似的设置:

It might also be worth noting that action mailer has a similar setting:

config.action_mailer.asset_host = 'https://abcd.cloudfront.net'

这篇关于Rails 3.2 asset_host 设置被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆