我正在开发一个在Heroku上托管的Ruby on Rails Web应用程序。我正在使用Zerb Foundation 5进行样式设计,在开发环境中效果很好。如果将环境更改为生产环境并重新启动服务器,则无法正确呈现Foundation组件。我相信这是一个Jquery问题。这是一个下拉菜单外观/在生产环境中如何显示的示例:
在生产环境中运行时,出现以下错误:
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
预先感谢,如果有什么需要帮助的地方,请告诉我,我不想用更多的代码弄乱这篇文章haha:)
答案 0 :(得分:2)
简单修复:
在 javascripts / applciation.js
- //= require rails-ujs
+ //= require jquery-ujs
预编译的资产,现在可以正常工作了。
答案 1 :(得分:0)
在production.rb
中:
config.assets.js_compressor = :uglifier
config.assets.compile = false
bundle exec rake assets:clean RAILS_ENV=production
和bundle exec rake assets:precompile RAILS_ENV=production