Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Heroku临时站点上未显示新图像资产_Ruby On Rails_Ruby_Git_Heroku_Asset Pipeline - Fatal编程技术网

Ruby on rails Heroku临时站点上未显示新图像资产

Ruby on rails Heroku临时站点上未显示新图像资产,ruby-on-rails,ruby,git,heroku,asset-pipeline,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_

更新:我刚刚发现,只有当我投入生产时,我的资产才会出现在暂存上

每当我添加新的映像资产、预编译它们并部署到暂存时,它们都不会出现。然而,一切都在本地和生产环境中运行。这是我的代码和添加新图像资产的过程。任何帮助都将不胜感激。我对此很陌生,一直在到处寻找答案

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
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
我如何为登台预编译资产

RAILS_ENV=staging bundle exec rake assets:precompile
我如何为生产预编译我的资产

RAILS_ENV=staging bundle exec rake assets:precompile
应用程序.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
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
需要文件。展开路径('../boot',文件)
需要“rails/all”
#需要Gemfile中列出的宝石,包括任何宝石
#您仅限于:测试、开发或:生产。
Bundler.require(*Rails.groups)
模块信息站点
类应用程序
我添加图像资源的过程:

  • 在应用程序/资产/图像中放置图像
  • 在布局中使用它(使用资产pipline:=image\u标记'image.png')
  • 本地检查(一切正常)
  • 使用
    RAILS\u ENV=staging bundle exec rake assets:precompile
  • 使用
    RAILS\u ENV=production bundle exec rake assets:precompile
  • 检查github,所有资产都已更新,我可以看到它们已预编译
  • git推送暂存主机
  • 现在,如果我查看staging,资产将返回一个显示图像名称的空图像框


    在我的过程中,我是否缺少什么?我应该采取不同的方法吗?

    转到config/application.rb。 查找字符串
    config.assets.enabled
    ,并将值设置为“true”。
    或者
    config.assets.initialize_on_precompile
    并设置为true。

    我尝试了这两种方法,但我的资产仍然没有加载。我甚至尝试删除我的public/assets文件夹并再次进行预编译。我注意到我的新资产正在被预编译,但没有得到服务。这与你提供给我的方法有关吗?谢谢你的帮助是的,我试过你描述的两种方法。您需要我提供的任何其他信息吗?请尝试将config.assets.compile设置为true。使用的是哪个rails版本?运气不好。我使用的是rails 4.2.1。我已经在我的问题中添加了application.rb,我希望这会有所帮助