1

私のアセットは Heroku でプリコンパイルされていません。私は杉で実行しており、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)

それで何かをしていますが、herokuから提供されたときの私のappliation.jsは次のようになります:

...
//= 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 アセットのコンパイルを有効にするにはどうすればよいですか?

更新

レポ 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

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 に答える