1

我的资产没有在 Heroku 上预编译。我在 cedar 上运行,并定义了 application.js 和 application.css,如(js):

...
//= require jquery
//= require jquery_ujs
//= require data_table
//= require_tree .

当我在我的机器上本地运行它时

bundle exec rake assets:precompile RAILS_ENV=production

它有效,js和css l。当我部署时,我看到:

-----> Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_b3aac0a4-54a9-4423-bba2-c15771931ae2/Rakefile:7)

   Asset precompilation completed (6.04s)

所以它在做某事,但我的 appliation.js 从 heroku 服务时仍然是这样的:

...
//= require jquery
//= require jquery_ujs
//= require data_table
//= require_tree .

我的 production.rb 看起来像这样:

  ...
    # Code is not reloaded between requests.
    config.cache_classes = true

    # Eager load code on boot. This eager loads most of Rails and
    # your application in memory, allowing both thread web servers
    # and those relying on copy on write to perform better.
    # Rake tasks automatically ignore this option for performance.
    config.eager_load = true

    # Full error reports are disabled and caching is turned on.
    config.consider_all_requests_local       = false
    config.action_controller.perform_caching = true

    # Enable Rack::Cache to put a simple HTTP cache in front of your application
    # Add `rack-cache` to your Gemfile before enabling this.
    # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
    # config.action_dispatch.rack_cache = true

    # Disable Rails's static asset server (Apache or nginx will already do this).
    config.serve_static_assets = false

    # Compress JavaScripts and CSS.
    config.assets.js_compressor = :uglifier
    # config.assets.css_compressor = :sass

    # Do not fallback to assets pipeline if a precompiled asset is missed.
    config.assets.compile = true

    # Generate digests for assets URLs.
    config.assets.digest = true

    # Version of your assets, change this if you want to expire all your assets.
    config.assets.version = '1.0'


    # Set to :debug to see everything in the log.
    config.log_level = :info

    config.i18n.fallbacks = true

    # Send deprecation notices to registered listeners.
    config.active_support.deprecation = :notify

    # Disable automatic flushing of the log to improve performance.
    # config.autoflush_log = false

    # Use default logging formatter so that PID and timestamp are not suppressed.
    config.log_formatter = ::Logger::Formatter.new
  ...

...

这是我在部署时看到的:

 -----> Ruby/Rails app detected
 -----> Using Ruby version: ruby-2.0.0
 -----> Installing dependencies using Bundler version 1.3.2
        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
        Using rake (10.1.0)
        Using i18n (0.6.5)
        Using multi_json (1.8.0)
        Using activesupport (3.2.6)
        Using builder (3.0.4)
        Using activemodel (3.2.6)
        Using erubis (2.7.0)
        Using journey (1.0.4)
        Using rack (1.4.5)
        Using rack-cache (1.2)
        Using rack-test (0.6.2)
        Using hike (1.2.3)
        Using tilt (1.4.1)
        Using sprockets (2.1.3)
        Using actionpack (3.2.6)
        Using mime-types (1.25)
        Using polyglot (0.3.3)
        Using treetop (1.4.15)
        Using mail (2.4.4)
        Using actionmailer (3.2.6)
        Using active_model_serializers (0.8.1)
        Using arel (3.0.2)
        Using tzinfo (0.3.37)
        Using activerecord (3.2.6)
        Using activeresource (3.2.6)
        Using addressable (2.3.5)
        Using extlib (0.9.16)
        Using autoparse (0.3.3)
        Using multi_xml (0.5.5)
        Using httparty (0.11.0)
        Using json (1.8.0)
        Using mini_portile (0.5.1)
        Using nokogiri (1.6.0)
        Using uuidtools (2.1.4)
        Using aws-sdk (1.5.8)
        Using bcrypt-ruby (3.0.1)
        Using climate_control (0.0.3)
        Using cocaine (0.5.1)
        Using coffee-script-source (1.6.3)
        Using execjs (2.0.1)
        Using coffee-script (2.2.0)
        Using rack-ssl (1.3.3)
        Using rdoc (3.12.2)
        Using thor (0.18.1)
        Using railties (3.2.6)
        Using coffee-rails (3.2.2)
        Using faker (1.2.0)
        Using multipart-post (1.2.0)
        Using faraday (0.8.8)
        Using flickraw (0.9.6)
        Using jwt (0.1.8)
        Using launchy (2.3.0)
        Using signet (0.4.5)
        Using google-api-client (0.6.4)
        Using jquery-rails (3.0.4)
        Using kgio (2.8.1)
        Using mono_logger (1.1.0)
        Using paperclip (3.5.1)
        Using pg (0.16.0)
        Using rack-protection (1.5.0)
        Using bundler (1.3.2)
        Using rails (3.2.6)
        Using raindrops (0.12.0)
        Using redis (3.0.4)
        Using redis-namespace (1.3.1)
        Using sinatra (1.4.3)
        Using vegas (0.1.11)
        Using resque (1.24.1)
        Using rufus-scheduler (2.0.24)
        Using resque-scheduler (2.0.1)
        Using sass (3.2.10)
        Using sass-rails (3.2.6)
        Using uglifier (2.2.1)
        Using unicorn (4.6.3)
        Using will_paginate (3.0.4)
        Your bundle is complete! It was installed into ./vendor/bundle
        Cleaning up the bundler cache.
 -----> Writing config/database.yml to read from DATABASE_URL
 -----> Preparing app for Rails asset pipeline
        Running: rake assets:precompile
        DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_1e4f5b44-48d7-48fc-b409-67b7c5e18c47/Rakefile:7)
        DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_1e4f5b44-48d7-48fc-b409-67b7c5e18c47/Rakefile:7)
        DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_1e4f5b44-48d7-48fc-b409-67b7c5e18c47/Rakefile:7)
        DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_1e4f5b44-48d7-48fc-b409-67b7c5e18c47/Rakefile:7)
        Asset precompilation completed (4.63s)
 -----> WARNINGS:
        Injecting plugin 'rails_log_stdout'
        Injecting plugin 'rails3_serve_static_assets'
        Add 'rails_12factor' gem to your Gemfile to skip plugin injection
        You have not declared a Ruby version in your Gemfile.
        To set your Ruby version add this line to your Gemfile:
        ruby '2.0.0'
        # See https://devcenter.heroku.com/articles/ruby-versions for more information."
 -----> Discovering process types
        Procfile declares types      -> web
        Default types for Ruby/Rails -> console, rake, worker

 -----> Compiled slug size: 50.7MB
 -----> Launching... done, v25
        http://NAME.herokuapp.com deployed to Heroku

所以这一切都应该是上帝,但没有运气。我需要做什么才能启用 slug 资产编译?

更新

创建了一个 repo https://github.com/whoisstan/asset-test.herokuapp.com和一个演示该行为的 heroku 应用程序:

http://asset-test.herokuapp.com/welcome/index

application.js 保持空白。

我需要如何描述我的生产环境?我不想在本地预编译。

https://github.com/whoisstan/asset-test.herokuapp.com/blob/master/config/environments/production.rb

4

2 回答 2

1

我会首先尝试确保标志:

config.assets.initialize_on_precompile = false

在您的生产环境配置中设置。如果这不能解决,您可以尝试在本地编译并将预编译的文件与应用程序一起部署到 heroku。最后,将新rails_12factorgem 添加到 gemfile 中的生产组也可能有意义。

于 2013-09-19T11:43:20.253 回答
0

在 heroku 支持的帮助下,我们找到了解决方案:

“与 Ruby 2.0 相关的链轮中存在一个错误,因此它无法正确编译 application.js: https ://github.com/sstephenson/sprockets/issues/352 。由于您使用的是 Rails 3.2.6,因此您的链轮是旧并导致此问题。要支持 Ruby 2.0,您应该使用最新的 Rails 3.2 版本:3.2.14 或升级到 Rails 4。

于 2013-11-03T13:00:47.557 回答