我在 heroku 上有一个 rails 3.2 应用程序。我已经尝试了我能找到的一切来尝试解决 javascripts 没有在生产模式下加载的事实。不过在开发中一切正常。此外,在部署到 heroku 时,预编译失败。但是,当我查看 prod 中的源代码时,我可以清楚地看到 javascripts 文件 (/assets/application-32fdbd115c5d59c7be2876c103063600.js) 正在加载并且有内容。
我已经尝试了所有我能想到和读过的设置。我不太确定该怎么做。这是我目前在 production.rb 中的设置:
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = false
config.assets.compile = true
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
在 environment.rb 中:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
App::Application.initialize!
应用程序.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 App
class Application < Rails::Application
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
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'
和我的宝石文件:
gem 'rails', '3.2.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'mysql2'
gem 'thin'
gem 'activerecord-postgresql-adapter'
gem 'devise'
gem 'paperclip', '~> 3.0'
gem 'haml'
gem 'activeadmin'
gem "meta_search", '>= 1.1.0.pre'
gem 'aws-sdk', '~> 1.3.4'
gem 'acts_as_list'
gem 'stripe'
gem 'sass-rails', '~> 3.2.3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'twitter-bootstrap-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :development do
gem 'debugger'
end
我所做的一切似乎都无法让它在我的本地机器或 heroku 上的生产模式下工作。但是,它在开发中工作得很好。