Heroku登台站点上未显示新图像资源

时间:2015-07-22 05:06:36

标签: ruby-on-rails ruby git heroku asset-pipeline

更新:我刚刚发现,只有当我投入生产时,我的资产才会出现在升级中。

每当我添加新图像资源,预编译它们并部署到暂存时,它们都不会出现。但是,一切都在本地和生产上有效。添加新图像资源时,这是我的代码和流程。任何帮助,将不胜感激。我对此非常陌生,一直在寻找答案。

staging.rb

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.action_mailer.default_url_options = { :host => 'http://site_name.herokuapp.com' }
  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  config.log_level = :debug
  config.action_controller.asset_host = Proc.new { |source|
    if source =~ /\b(.png|.jpg|.gif|.svg)\b/i
      "http://key.cloudfront.net"
    end
  }
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.active_record.dump_schema_after_migration = false
end

我如何预编译资产以进行暂存

RAILS_ENV=staging bundle exec rake assets:precompile

我如何预编制资产以进行制作

RAILS_ENV=staging bundle exec rake assets:precompile

application.rb中

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module InfoSite
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those     specified here.
    # Application configuration should go into files in   config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active   Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone   names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    config.serve_static_files = true
    config.assets.compile = true
    config.assets.configure do |env|
      if Rails.env.development? || Rails.env.test?
        env.cache = ActiveSupport::Cache.lookup_store(:memory_store)
      end
  end
    # The default locale is :en and all translations from     config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*. {rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Do not swallow errors in after_commit/after_rollback callbacks.
    config.active_record.raise_in_transactional_callbacks = true
  end
end

我添加图片资源的流程:

  1. 将图片放入app / assets / images
  2. 在布局中使用它(使用资产管道:= image_tag'image.png')
  3. 在本地检查(一切正常)
  4. 使用RAILS_ENV=staging bundle exec rake assets:precompile
  5. 使用RAILS_ENV=production bundle exec rake assets:precompile
  6. 检查github,更新所有资产,我可以看到他们已经预编译了
  7. git push staging master
  8. 现在,如果我查看暂存,资产会返回一个显示图像名称的空图像框。

    我的过程中是否有遗漏的东西?我应该对此采取不同的方法吗?

1 个答案:

答案 0 :(得分:0)

转到config / application.rb。 找到字符串config.assets.enabled并将值设置为&#39; true&#39;。 或config.assets.initialize_on_precompile并设置为true。