Javascripts 不能在 Heroku Rails 4.2 上使用 Zurb Foundation 5 部署,但在开发中工作
Javascripts not working on Heroku Rails 4.2 deploy with Zurb Foundation 5, but work in development
我是 运行 Rails 4.2.3 和 'foundation-rails' 5.5.2 gem,我无法在 Heroku 上获得它 运行 .我的应用程序在本地运行良好,但是当尝试使用 Foundation 5 将我的应用程序部署到 Heroku 时,javascripts 没有加载。
CSS 在 Heroku 上看起来不错,但是模态等功能无法正常工作,并且控制台没有显示我的 application.js
中指定的任何 javascripts 运行 ] 文件。
Modernizr.js
和 Jquery-2.1.4
是 运行
我在任何地方都没有看到任何错误,我使用 bundle exec rake assets:precompile
预编译了资源,这些资源似乎已经过预编译。
如何加载 javascript 以便页面正常工作?
application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.serializeJSON
//= require jquery.bind_with_delay
//= require_tree .
//= require_self
//= require gifffer.min
//= require imagesloaded.min
//= require google.jsapi
//= require foundation
//= stub bookmarklet/modal_bookmarklet
$(function() {
$(document).foundation();
});
production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
gem文件
source "https://rubygems.org"
gem "rails", "4.2.3"
gem "unicorn"
gem "mysql2", ">= 0.3.14"
gem "pg"
gem "thinking-sphinx", "~> 3.1.2"
gem "jquery-rails"
gem "dynamic_form"
gem "exception_notification"
gem "bcrypt", "~> 3.1.2"
gem "nokogiri", "= 1.6.6.2"
gem 'mini_portile', '~>0.6.2'
gem "htmlentities"
gem "rdiscount"
gem "oauth"
gem "mail"
gem 'metainspector', :git => 'https://github.com/jaimeiniesta/metainspector.git'
gem 'material_icons'
gem "bower-rails","~> 0.9.2"
gem 'launchy'
gem 'sass', '~> 3.4.15'
gem 'foundation-rails', '~> 5.5.2'
gem 'compass', '~>1.0.3'
gem "uglifier", ">= 1.3.0"
gem 'coffee-rails', '~> 4.1.0'
gem 'modernizr-rails', '~>2.7.1'
gem 'jbuilder', '~> 2.3.0'
gem 'multi_json', '~>1.11.1'
gem 'rails_12factor'
gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"
gem 'aws-sdk'
gem 'figaro'
gem 'omniauth-facebook'
gem 'pg_search'
gem 'kaminari'
gem 'ejs'
gem 'yt', '~> 0.25.0'
group :doc do
gem 'sdoc', require: false
end
group :test, :development do
gem "rspec-rails", "~> 3.3.2"
gem "machinist"
gem "sqlite3"
gem "faker"
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
end
编辑
看起来我收到一条错误 "Uncaught TypeError: $(...).foundation is not a function"。我不确定这是否与 Heroku 或我的配置有关。为什么这会在本地工作,而不是在 Heroku 上?
您在加载基础 JS 之前进行了 require_self
调用,并且您正在尝试在清单文件中使用基础 JS。尝试在所有其他指令之后移动 require_self
指令。
我是 运行 Rails 4.2.3 和 'foundation-rails' 5.5.2 gem,我无法在 Heroku 上获得它 运行 .我的应用程序在本地运行良好,但是当尝试使用 Foundation 5 将我的应用程序部署到 Heroku 时,javascripts 没有加载。
CSS 在 Heroku 上看起来不错,但是模态等功能无法正常工作,并且控制台没有显示我的 application.js
中指定的任何 javascripts 运行 ] 文件。
Modernizr.js
和 Jquery-2.1.4
是 运行
我在任何地方都没有看到任何错误,我使用 bundle exec rake assets:precompile
预编译了资源,这些资源似乎已经过预编译。
如何加载 javascript 以便页面正常工作?
application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.serializeJSON
//= require jquery.bind_with_delay
//= require_tree .
//= require_self
//= require gifffer.min
//= require imagesloaded.min
//= require google.jsapi
//= require foundation
//= stub bookmarklet/modal_bookmarklet
$(function() {
$(document).foundation();
});
production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
gem文件
source "https://rubygems.org"
gem "rails", "4.2.3"
gem "unicorn"
gem "mysql2", ">= 0.3.14"
gem "pg"
gem "thinking-sphinx", "~> 3.1.2"
gem "jquery-rails"
gem "dynamic_form"
gem "exception_notification"
gem "bcrypt", "~> 3.1.2"
gem "nokogiri", "= 1.6.6.2"
gem 'mini_portile', '~>0.6.2'
gem "htmlentities"
gem "rdiscount"
gem "oauth"
gem "mail"
gem 'metainspector', :git => 'https://github.com/jaimeiniesta/metainspector.git'
gem 'material_icons'
gem "bower-rails","~> 0.9.2"
gem 'launchy'
gem 'sass', '~> 3.4.15'
gem 'foundation-rails', '~> 5.5.2'
gem 'compass', '~>1.0.3'
gem "uglifier", ">= 1.3.0"
gem 'coffee-rails', '~> 4.1.0'
gem 'modernizr-rails', '~>2.7.1'
gem 'jbuilder', '~> 2.3.0'
gem 'multi_json', '~>1.11.1'
gem 'rails_12factor'
gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"
gem 'aws-sdk'
gem 'figaro'
gem 'omniauth-facebook'
gem 'pg_search'
gem 'kaminari'
gem 'ejs'
gem 'yt', '~> 0.25.0'
group :doc do
gem 'sdoc', require: false
end
group :test, :development do
gem "rspec-rails", "~> 3.3.2"
gem "machinist"
gem "sqlite3"
gem "faker"
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
end
编辑 看起来我收到一条错误 "Uncaught TypeError: $(...).foundation is not a function"。我不确定这是否与 Heroku 或我的配置有关。为什么这会在本地工作,而不是在 Heroku 上?
您在加载基础 JS 之前进行了 require_self
调用,并且您正在尝试在清单文件中使用基础 JS。尝试在所有其他指令之后移动 require_self
指令。