SO投稿で概説されているのと基本的に同じ問題が発生しています。
jQuery スクリプトが本番環境で読み込まれない (Heroku - cedar スタック)
開発環境では、私の JavaScript がページに正しく組み込まれています。
<link type="text/css" rel="stylesheet" media="all" href="/assets/rails_admin/imports.css?body=1">
<link type="text/css" rel="stylesheet" media="all" href="/assets/rails_admin/rails_admin.css?body=1">
<script type="text/javascript" src="/assets/jquery.js?body=1">
<script type="text/javascript" src="/assets/jquery_ujs.js?body=1">
<script type="text/javascript" src="/assets/jquery.iframe-transport.js?body=1">
<script type="text/javascript" src="/assets/jquery.remotipart.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.effect.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.core.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.widget.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.mouse.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.sortable.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.position.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.menu.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.autocomplete.js?body=1">
<script type="text/javascript" src="/assets/jquery.ui.datepicker.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/jquery.ui.timepicker.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ra.datetimepicker.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/jquery.colorpicker.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ra.filter-box.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ra.filtering-multiselect.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ra.filtering-select.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ra.remote-form.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/jquery.pjax.js?body=1">
<script type="text/javascript" src="/assets/jquery_nested_form.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ra.nested-form-hooks.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-transition.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-affix.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-alert.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-button.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-carousel.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-collapse.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-dropdown.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-modal.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-scrollspy.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-tab.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-tooltip.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-popover.js?body=1">
<script type="text/javascript" src="/assets/bootstrap-typeahead.js?body=1">
<script type="text/javascript" src="/assets/bootstrap.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ra.widgets.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/ui.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/themes/default/ui.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/custom/ui.js?body=1">
<script type="text/javascript" src="/assets/rails_admin/rails_admin.js?body=1">
しかし、Heroku (Cedar スタック) の Production では、次のようになります。
<html>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<meta content='NONE,NOARCHIVE' name='robots'>
<meta content="authenticity_token" name="csrf-param" />
<meta content="mJAzj+IxBGxFd4vVR9EZKX9a0CL9zSugp5a13vcCOGY=" name="csrf-token" />
<link href="/assets/rails_admin/rails_admin-babb206bf505b710a7e6ec10b27d3190.css" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/rails_admin/rails_admin-315877c5aae48e12a1abd274be846d08.js" type="text/javascript"></script>
</head>
私の調査によると、誰もが解決策としてアセットをプリコンパイルすることを指摘しているようですが、私は何十もの解決策を試しましたが、問題を解決したものはありません。
次のコマンドを使用して、Heroku にプッシュする前にアセットをプリコンパイルしようとしました。
RAILS_ENV=production bundle exec rake assets:precompile
しかし、問題はまだ表示されます
関連するファイルを次に示します。
Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'rails_admin'
gem 'cancan'
gem 'bootstrap-sass'
gem 'jquery-rails'
gem "devise"
group :development, :test do
gem 'rspec-rails'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-rails'
end
アプリケーション.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
アプリケーション.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module MaterialsCalculatorApp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
end
end
開発中はすべて正常に動作します。Heroku にデプロイするだけで問題が発生します。この問題のデバッグに役立つ可能性のある追加のファイルがあればお知らせください。提供します。