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

问题描述 投票:1回答:0

在开发过程中,我所有的图像,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, '[email protected]: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

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

image ruby-on-rails-4 nginx capistrano3
© www.soinside.com 2019 - 2024. All rights reserved.