【发布时间】:2020-10-10 17:33:49
【问题描述】:
如果有任何帮助,我将不胜感激。我最近将我的应用程序更新到 rails 5.2.3(从 4.0.1 开始),并注意到当我向资产/图像添加新图像时,它无法在生产中显示。我最终运行了 rake assets:clobber 并尝试使用 rake assets:precompile 重建我的资产。不幸的是,现在我所有的资产都死了。
当我启动 Rails 服务器并转到 localhost:3000 时,开发中的一切都按预期工作
我尝试修改 production.rb 配置文件,但没有取得任何进展。任何帮助将不胜感激,我在这个网站上做了很多工作,它用于世界各地的医疗专业人员。无论如何,我都不是专业的程序员。我注意到运行后
assets:precompile RAILS_ENV=production
创建了一个新的 public/assets 文件夹,但只包含三个文件:
- .sprockets-manifest-.....json
- 清单-....js
- 清单-.....js.gz
而不是我的资产/图像文件夹中的所有图像
production.rb
BoardsApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
end
宝石文件
source 'https://rubygems.org'
ruby '2.6.3'
gem 'rails', '5.2.3'
gem 'puma'
gem 'bootstrap-sass'
gem 'bootstrap-switch-rails'
gem 'nokogiri'
gem 'pg', '0.21.0'
gem 'haml'
gem 'friendly_id'
gem 'rake'
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'selenium-webdriver'
gem 'capybara'
end
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :doc do
gem 'sdoc', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
更新 我从 Heroku 上的早期部署中恢复了网站,所以至少现在它还活着,但我还没有解决如何更新的问题,因为我的图像似乎都没有被编译。
当我在生产环境中运行 rails server 时,我得到了这个错误:
ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):
ActionController::RoutingError (No route matches [GET] "/javascripts/application.js"):
而在开发中,一切都按预期加载。 更新 已解决! 感谢您建议查看 heroku 日志。我发现了错误:
Asset `application.css` was not declared to be precompiled in production
从那里我找到了https://github.com/rails/sprockets-rails/issues/458这个讨论。
我将 sprockets-rails gem 降级到 2.3.3。并运行 rake assets:precompile ,一切正常。
【问题讨论】:
-
在这样做之后,应用程序完全崩溃了,我得到了我们很抱歉,但出现了问题页面。
-
当您遇到出现问题的页面时,您应该查看日志文件以找出究竟出了什么问题,然后您可以着手修复它,所以发布您得到的实际错误跨度>
-
assets:clobber 将清空您的资产文件夹。您将需要重新编写所有 css 和 javascript 并重新复制到您的图像中,然后预编译资产。因此,从旧项目文件夹中复制所有资产并尝试再次编译。每次添加资产并发布到生产环境时,都必须编译
-
app/assets 文件夹仍然像往常一样包含我所有的图像和 css.scss 文件和 js.coffee 文件。该应用程序在开发中完美运行。在我升级到 Rails 5 之前,生产中出现了一些从未发生过的问题。由于某种原因,rake assets:precompile 似乎无法编译。
-
您在编译资产时看到了什么错误或错误?
标签: ruby-on-rails ruby-on-rails-5 assets