Foundation/Jquery 不在生产环境中工作,在开发中工作

Foundation/Jquery not working in Production env, works in development

我正在开发 Ruby on Rails Web 应用程序,该应用程序托管在 Heroku 上。我正在使用 Zerb Foundation 5 进行样式设计,它在开发环境中运行良好。如果我将环境更改为生产环境并重新启动服务器,则 Foundation 组件无法正确呈现。我认为这是一个 Jquery 问题。这是下拉菜单的外观/它们在生产中的显示方式的示例:

working dropdown

not working dropdown

当 运行 在生产中时,我收到以下错误:

Uncaught TypeError: ht.each is not a function
at VM417 application-d4dfc26bd5c2527cd0b1b3ce283f89526f6a65ed0527799d75ae98ccd0415867.js:1
at VM417 application-d4dfc26bd5c2527cd0b1b3ce283f89526f6a65ed0527799d75ae98ccd0415867.js:1
at VM417 application-d4dfc26bd5c2527cd0b1b3ce283f89526f6a65ed0527799d75ae98ccd0415867.js:1

这让我看到了这条线:

"function" == typeof Symbol && (ht.fn[Symbol.iterator] = nt[Symbol.iterator]),
ht.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "), function(t, e) {
    lt["[object " + e + "]"] = e.toLowerCase()
});

我试过预编译和清理资产:

$ rails assets:clean
$ RAILS_ENV=production bundle exec rails assets:precompile

生产数据库已创建并播种。我对环境配置文件做了一些修改,试图调试这个问题。由于问题仅在生产中出现,因此对我来说这就是问题的来源。

config/environments/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.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  config.assets.js_compressor = :uglifier
  config.assets.digest = true

  config.assets.compile = true

  config.active_storage.service = :local

  config.log_level = :debug

  config.log_tags = [ :request_id ]

  config.action_mailer.perform_caching = false

  config.i18n.fallbacks = true

  config.active_support.deprecation = :notify

  config.log_formatter = ::Logger::Formatter.new

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

  config.active_record.dump_schema_after_migration = false
end

javascripts/applciation.js

//= require jquery
//= require rails-ujs
//= require turbolinks
//= require foundation
//= require_tree .

$(document).on('turbolinks:load', function() {
    $(function(){ $(document).foundation(); });
});

根据研究,我遇到此错误的可能原因是:

我一直在学习 heroku 教程:

https://devcenter.heroku.com/articles/rails-asset-pipeline#troubleshooting

https://devcenter.heroku.com/articles/rails-4-asset-pipeline

在此先感谢,如果有任何有助于包含的内容,请告诉我,我不想用更多代码弄乱 post 哈哈 :)

简单修复:

javascripts/applciation.js

- //= require rails-ujs
+ //= require jquery-ujs

预编译资源,现在可以正常工作了。

production.rb中:

  1. 我评论这行:config.assets.js_compressor = :uglifier
  2. 设置为假:config.assets.compile = false
  3. 运行 在控制台中:bundle exec rake assets:clean RAILS_ENV=productionbundle exec rake assets:precompile RAILS_ENV=production
  4. 重启服务器