Rails 4.2:图像路径在生产中没有指纹,Capistrano部署

时间:2015-07-16 00:42:36

标签: image ruby-on-rails-4 nginx capistrano3

在开发中,我的所有图像,CSS和JS都正常加载。在制作中,我的CSS和JS正在加载。背景图像通过CSS加载精细,图像写为:

image_tag "foo.png"

也可以正常加载并显示指纹。但是,图像写为:

image_tag @test_question.question.image

未在生产中进行指纹识别(图像名称记录在数据库中)。但是,这在开发中效果很好。

在开发中我看到:

<img src="/assets/picture1-a2bac24ba737cf267b5cc29f9fdaea33.jpg">

在制作中我看到:

<img src="/images/picture1.jpg">

包括图像在内的资产在我的生产服务器上的相应目录中进行编译和指纹识别,它们在视图中没有被指纹识别或正确调用。我正在使用Rails 4.2,nginx和unicorn,并使用Capistrano 3.2进行部署。

编辑:

我有图像子目录。以下是我的初始化程序:

初​​始化/ assets.rb

Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
  Rails.application.config.assets.paths << path
end

当我评论这一点时,开发中的行为与生产中的行为相同。所以,我想问题是这个代码在生产环境中没有工作/被读取。有什么建议吗?

环境/ production.rb

config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = false
config.assets.digest = true
config.assets.version = Digest::MD5.hexdigest(Date.new.to_s)
config.assets.initialize_on_precompile = true
config.i18n.fallbacks = true

deploy.rb

lock '3.2.1'

set :application, 'foobar'
set :deploy_user, 'deploy'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call

# Default deploy_to directory is /var/www/my_app
# set :deploy_to, '/var/www/my_app'
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"

# Default value for :scm is :git
set :scm, :git
set :repo_url, 'git@github.com:foobar/baz.git'

set :rbenv_type, :system
set :rbenv_ruby, '2.2.2'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}

set :keep_releases, 2

set :linked_files, %w{config/database.yml config/secrets.yml config/application.yml}

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

# Default value for :format is :pretty
set :format, :pretty

# what specs should be run before deployment is allowed to
# continue, see lib/capistrano/tasks/run_tests.cap
set :tests, []

# which config files should be copied by deploy:setup_config
# see documentation in lib/capistrano/tasks/setup_config.cap
# for details of operations
set(:config_files, %w(
  nginx.conf
  log_rotation
  monit
  unicorn.rb
  unicorn_init.sh
  application.yml
  database.yml
))

# which config files should be made executable after copying
# by deploy:setup_config
set(:executable_config_files, %w(
  unicorn_init.sh
))

# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc.

set(:symlinks, [
  {
    source: "nginx.conf",
    link: "/etc/nginx/sites-enabled/{{full_app_name}}"
  },
  {
    source: "unicorn_init.sh",
    link: "/etc/init.d/unicorn_{{full_app_name}}"
  },
  {
    source: "log_rotation",
    link: "/etc/logrotate.d/{{full_app_name}}"
  },
  {
    source: "monit",
    link: "/etc/monit/conf.d/{{full_app_name}}.conf"
  }
])

namespace :deploy do

  before :deploy, "deploy:check_revision"

  # compile assets locally then rsync
    #after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
  #after :finishing, 'deploy:cleanup'
  # remove the default nginx configuration as it will tend
  # to conflict with our configs.
    before 'deploy:setup_config', 'nginx:remove_default_vhost'
  # reload nginx to it will pick up any modified vhosts from
  # setup_config
    after 'deploy:setup_config', 'nginx:reload'
  # Restart monit so it will pick up any monit configurations
  # we've added
    after 'deploy:setup_config', 'monit:restart'
  # As of Capistrano 3.1, the `deploy:restart` task is not called
  # automatically.
    after 'deploy:publishing', 'deploy:restart'

    after "deploy:restart", "deploy:cleanup"
end

我真的看不出这里有什么问题。有什么建议吗?

0 个答案:

没有答案