rake资产:当将rails5 app推送到heroku时,预编译失败了

时间:2016-09-17 17:49:44

标签: ruby heroku assets ruby-on-rails-5

我用ruby 2.3.1完成了我的rails5应用程序并尝试将其推送到heroku并且我发现了这个错误:

remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        DEPRECATION WARNING: `config.static_cache_control` is deprecated and will be removed in Rails 5.1.
remote:        Please use
remote:        `config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=31536000' }`
remote:        instead.
remote:        (called from <class:Application> at /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/config/application.rb:15)
remote:        rake aborted!
remote:        ArgumentError: wrong number of arguments (given 2, expected 1)
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/static.rb:16:in `initialize'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/heroku_rails_deflate-1.0.3/lib/heroku_rails_deflate/serve_zipped_assets.rb:16:in `new'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/heroku_rails_deflate-1.0.3/lib/heroku_rails_deflate/serve_zipped_assets.rb:16:in `initialize'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:35:in `new'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:35:in `build'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `block in build'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `each'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `inject'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `build'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:508:in `block in app'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:504:in `synchronize'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:504:in `app'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:37:in `block in <module:Finisher>'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/config/environment.rb:5:in `<top (required)>'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:328:in `require'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:328:in `require_environment!'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
remote:        /tmp/build_a89fafde7de9b83ca3fda752b1492a0d/vendor/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => environment
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to cdcnv.
remote:
To https://git.heroku.com/cdcnv.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cdcnv.git'

我尝试删除Gemfile.lock和ruby bundle install,但再次看到同样的错误。

之后我尝试修改我的config/production.rb,但没有任何反应,这就是我的config/production.rb

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.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 threaded 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

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = true

  # 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

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "my_gem_site_#{Rails.env}"
  config.action_mailer.perform_caching = false

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

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

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

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

这是我的Gemfile

source 'https://rubygems.org'
ruby '2.3.1'

# Use credit_debit_card_number_validator as the default card number validator
gem 'credit_debit_card_number_validator'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '= 0.19.0.pre20160904200247'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console'
end

group :production do
  gem 'heroku_rails_deflate'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

我没有在rails5中更改任何内容默认应用程序只添加一个带有两种方法的控制器,只有一个视图。

任何想法?

1 个答案:

答案 0 :(得分:3)

Finnaly我通过从heroku_rails_deflate移除Gemfile gem并删除Gemfile.lock并重新运行bundle install然后推送到heroku来解决此问题。

您可以从以下网址查看该应用:http://cdcnv.herokuapp.com