资产管道没有生产,尝试了一切

时间:2012-07-03 06:26:23

标签: ruby-on-rails asset-pipeline

我在heroku上有一个rails 3.2 app。我已经尝试了所有我能找到的东西,试图解决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!

application.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'

和我的gemfile:

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上的生产模式下工作。但是,它在开发中效果很好。

2 个答案:

答案 0 :(得分:2)

我终于想出了如何解决这个问题,虽然我不知道修复有多好。基本上,问题是将.js文件压缩到application.js中会导致问题。在production.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

这解决了这个问题。但是,现在它代替了application.js,它列出了所有资产文件。我不确定这是否存在任何长期问题。

答案 1 :(得分:1)

在您的生产包装盒上尝试过:RAILS_ENV rake assets:precompile