rails prod中的image_path问题,没有自定义域,没有指纹,路径错误

时间:2014-02-26 16:42:00

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

这是rails 3.2.13 app。

我很困惑这里的问题是什么。任何帮助深表感谢。 我在这个位置有我的形象:

app/assets/images/icons/apple-touch-icon-precomposed.png

这是在layout.html.erb中:

<link rel="apple-touch-icon-precomposed" href="<%= image_path("icons/apple-touch-icon-precomposed.png") %>" />

在开发中它正确链接:

<link ... href="/assets/icons/apple-touch-icon-precomposed.png" />

生产中

it does not link correctly:
<link ... href="/icons/apple-touch-icon-precomposed.png" />
what i am expecting:    
<link ... href="http://asset.domain.com/assets/icons/apple-touch-icon-precomposed-5796a048f16a314924adbb237adf88d6.png" />

当我浏览生产服务器时,我在正确的位置看到了带有缩略图的图像:

public/assets/icons/apple-touch-icon-precomposed-5796a048f16a314924adbb237adf88d6.png

这是我的config/environments/production.rb

Aliencom::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = 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 = false

  # Compress JavaScripts and CSS
  config.assets.compress = true

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

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

  # Defaults to nil and saved in location specified by config.assets.prefix
  # config.assets.manifest = YOUR_PATH

  # Specifies the header that your server uses for sending files
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # See everything in the log (default is :info)
  config.log_level = :debug

  # Prepend all log lines with the following tags
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server
  config.action_controller.asset_host = 'http://asset.domain.com'

  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)

  config.assets.precompile += ['head.js']
  config.assets.precompile += ['libs/respond.src.js']
  config.assets.precompile += ['libs/jquery-1.10.2.js']
  config.assets.precompile += ['libs/swfobject.js']
  config.assets.precompile += ['libs/greensock/TweenMax.min.js']
  config.assets.precompile += ['libs/greensock/plugins/ScrollToPlugin.min.js']

  # Add the fonts and swfs path
  config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
  config.assets.paths << Rails.root.join('app', 'assets', 'swfs')

  # Disable delivery errors, bad email addresses will be ignored
  # config.action_mailer.raise_delivery_errors = false

  # Enable threaded mode
  # config.threadsafe!

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation can not be found)
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify

  # Log the query plan for queries taking more than this (works
  # with SQLite, MySQL, and PostgreSQL)
  # config.active_record.auto_explain_threshold_in_seconds = 0.5



  Paperclip::Attachment.default_options.update({
       #:url => "i/:class/:attachment/:basename_:style_:hash.:extension",
       # :url => "/system/:class/:attachment/:id_partition/:style/:basename.:extension",
       #:url => "/system/v2/:class/:attachment/:id/:style_:created_at.:extension",
       :use_timestamp => false,
       :url => "//assets.staging.aliencom.net/system/v3/:class_:attachment/:id/:basename_:style.:extension",
       :path => ":rails_root/public/system/v3/:class_:attachment/:id/:basename_:style.:extension",
       :hash_secret => "P/IbDQ4t2qYNLCKyVREvRhyRPWYHn3CW3fAsIGYsnAa3OfWBJeIE91gW9ZyLWZPBW+TlqI278yLtGA7BIZB+DTR9Bp9J0usbFMn7mCh1aLAn2WKzZYrrJZ0QcFL5TEkYhDISKymd34bwS0x2zOhdzeKaSkQn9iXidvQ++Pt0YBg="
   })

end

这是来自capistrano(capistrano 3)部署任务

...
INFO [231ef199] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile on 97.107.134.133
DEBUG [231ef199] Command: cd /var/www/ac_staging/releases/20140226162225 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=1.9.3-p448 RAILS_ENV=staging ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG [231ef199]    /home/deploy/.rbenv/versions/1.9.3-p448/bin/ruby /var/www/ac_staging/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
INFO [231ef199] Finished in 95.166 seconds with exit status 0 (successful).
...

1 个答案:

答案 0 :(得分:0)

在生产中,我的经验是从PUBLIC目录加载的文件未编译。 尝试将图像放在PUBLIC目录中,并使用文件名完整的相应文件夹。

因此,/icons/apple-touch-icon-precomposed.png将其放入/public/assets/icons/apple-touch-icon-precomposed.png尝试放入非编译图像。