gpt4 book ai didi

ruby-on-rails - Heroku 暂存站点上未显示新图像 Assets

转载 作者:太空宇宙 更新时间:2023-11-03 16:46:45 25 4
gpt4 key购买 nike

更新:我刚刚发现,只有当我 push 生产时,我的 Assets 才会出现在暂存中。

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

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

我如何为暂存预编译我的 Assets

RAILS_ENV=staging bundle exec rake assets:precompile

我如何为生产预编译我的 Assets

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

我添加图像 Assets 的过程:

  1. 将图片放在 app/assets/images 中
  2. 在布局中使用它(使用 Assets 管道:= 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,所有 Assets 都更新了,我可以看到它们已经预编译
  7. git push 暂存大师

现在,如果我查看暂存, Assets 会返回一个显示图像名称的空图像框。

我的流程中是否遗漏了什么?我应该对此采取不同的方法吗?

最佳答案

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

关于ruby-on-rails - Heroku 暂存站点上未显示新图像 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31554262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com