资产管道无法在生产上工作,尝试了每一个



我在heroku上有一个rails 3.2应用程序。我已经尝试了我能找到的一切来尝试解决 javascript 未在生产模式下加载的事实。不过,在开发中一切正常。此外,部署到 heroku 时,预编译会失败。但是,当我查看 prod 中的源代码时,我可以清楚地看到 javascripts 文件 (/assets/application-32fdbd115c5d59c7be2876c103063600.js) 加载并包含内容。

我已经尝试了我能想到并阅读过的所有设置。我不太确定该怎么办。这是我目前在生产.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 上的生产模式下工作。 但是,它在开发中工作得很好。

我终于想出了解决这个问题的方法,尽管我不知道它有多好。基本上,问题是将.js文件压缩到应用程序中.js导致了问题。在生产.rb中,我把这个:

  config.serve_static_assets = false
  # Compress JavaScripts and CSS
  config.assets.compress = false
  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true
  # Generate digests for assets URLs
  config.assets.digest = true
  config.assets.debug = true

这解决了问题。 但是,现在它不是应用程序.js,而是列出所有资产文件。 我不确定这是否有任何长期问题。

在您的生产盒上,您是否尝试过: RAILS_ENV rake assets:precompile

相关内容

最新更新