我有一个最近从Rails 4.2升级到5.2的应用程序。它使用的是Ruby 2.4.5。升级期间,我也从使用Thin切换为Puma。规格正在运行并通过,在本地我没有任何问题。但是,当部署到生产环境时,我所有的资产都停止工作。没有错误消息或异常发生,只是不再提供这些消息或异常,所以我只有空白页应该代替资产。
Setting config.assets.compile = true以及添加config.assets.debug = true在技术上是可行的,但是每个页面一旦部署就需要花费两分钟以上的时间来加载,因此显然这不是可行的解决方案。 Removing js_compressor = :uglifier导致“ ActionView :: Template :: Error(资产管道中不存在资产“ can_channels / index.js”。)”的新错误,即使Rails.application.config.assets.paths显示生产和发展都走同一条路。 我尝试过手动进行预编译,但结果没有变化。我可以通过将我的development.rb配置替换为生产环境中的配置来本地复制。
这是我的开发。rb:
# frozen_string_literal: true
Rails.application.configure do
config.action_mailer.default_url_options = { host: 'localhost', port: '3000' }
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.log_to = %w(stdout file)
config.log_level = :debug
config.show_log_configuration = true
config.web_console.whitelisted_ips = '10.101.0.0/16'
end
production.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.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.enabled = true
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
config.log_to = %w(stdout file)
config.show_log_configuration = true
end
assets.rb
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.paths << Rails.root.join('node_modules')
Rails.application.config.assets.precompile += %w[can_channels/* can_channels/index.js]
Rails.application.config.assets.precompile += %w[copy_text.js]
Rails.application.config.assets.precompile += %w[hardware_changes.js]
Rails.application.config.assets.precompile += %w[helpers/*]
Rails.application.config.assets.precompile += %w[burn_config.css]
Rails.application.config.assets.precompile += %w[burn_config/*]
Rails.application.config.assets.precompile += %w[services/*]
Rails.application.config.assets.precompile += %w[templates/*]
Rails.application.config.assets.precompile += %w[test_steps/*]
application.js:
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require angular/angular
//= require angular-animate/angular-animate
//= require angular-sanitize/angular-sanitize
//= require angular-rails-templates
//= require angular-route/angular-route
//= require angular-ui-bootstrap-tpls
//= require angular-ui-validate/dist/validate
//= require_tree ./test_sets/modules
//= require_tree ./test_sets/factories
//= require_tree ./test_sets/controllers
//= require_tree ./test_sets/directives
//= require_tree ./templates
//= require formvalidation/framework/bootstrap
//= require bootstrap-multiselect
//= require burn_config
//= require_tree ./burn_config
//= require js-routes
//= require_tree ./dotiw
//= require tinymce
//= require egg
//We do not use require_tree here, as we want to only load certain javascript for controller specific pages
//= require websocket_rails/main
我希望在Rails 5中处理资产的方式发生某些变化,这与我的应用程序中的某些发生冲突,但是我对这些想法一无所知。其他人是否遇到过类似的问题,或者知道如何解决?