加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 忽略Rails 3.2 asset_host设置

发布时间:2020-12-17 02:13:49 所属栏目:百科 来源:网络整理
导读:我的生产环境 – # 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
我的生产环境 –

# 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到资产主机.

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设置,但仍然无法识别设置.

解决方法

你试过设置指定的配置吗?

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

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

值得注意的是,动作邮件具有类似的设置:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读