【问题标题】:rake assets:precompile stuckrake assets:预编译卡住
【发布时间】:2014-01-02 11:05:17
【问题描述】:

几天前,我注意到 jquery 日历在我的部署站点 (heroku) 上不起作用。在挖掘问题时,我注意到我的开发服务器上的站点源有大约 100 个与引导程序相关的脚本标签(我正在使用 twitter 引导程序 css),但在产品服务器上。我有 4 个脚本标签。在搜索时,我发现我应该在我的 rails 控制台 fo 资产管道上运行 rake assets:precompile。但是在运行时它需要很长时间,上次花了 6 个小时,我不得不中止它。

参考了很多网站和帖子,我发现我应该将config.serve_static_assets改为trueconfig.assets.compile改为true。但问题仍然存在。我还尝试从gem 中删除jquery-rails/jquery-ui-rails,但问题仍然存在。 这是我的config/environmnets/production.rb

ProductRecall::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

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

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

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # 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



  # 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

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

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

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

  # Log the query plan for queries taking more than this (works
  # with SQLite, MySQL, and PostgreSQL)
  # config.active_record.auto_explain_threshold_in_seconds = 0.5

  config.action_controller.perform_caching  = false
end

我的config/application.rb 看起来像这样

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

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 ProductRecall
  class Application < Rails::Application

    # Configure the default encoding used in templates for Ruby 1.9.
    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

    # Enforce whitelist mode for mass assignment.
    # This will create an empty whitelist of attributes available for mass-assignment for all models
    # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
    # parameters by using an attr_accessible or attr_protected declaration.
    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'
    config.action_mailer.default_url_options = { host: 'localhost:3000' }
  end
end

这是我的 Gem 文件:

source 'https://rubygems.org'

gem 'rails', '3.2.13'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'therubyracer', :platforms => :ruby, :platforms => :ruby
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'bootstrap-datepicker-rails'
gem "google_visualr", "~> 2.1.0" 
gem 'twitter-bootstrap-rails'
gem "galetahub-simple_captcha", :require => "simple_captcha"
gem 'rufus-scheduler'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.11.0'
end

group :development do
  gem 'annotate', '2.5.0'
end

group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.2'

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '4.1.0'
  gem 'cucumber-rails', '1.2.1', :require => false
  gem 'database_cleaner', '0.7.0'
end

#gem 'jquery-ui-rails'

group :production do
  gem 'pg', '0.12.2'
end

请让我知道这里出了什么问题。因为我 2 天以来一直没有任何线索

【问题讨论】:

  • 解决此类问题的最佳方法是删除功能,直到它正常工作。我猜这可能是 Gem 的问题,但你只能通过测试来判断
  • 意味着我应该删除我没有在我的应用程序中使用的宝石??
  • 我的意思是您应该暂时禁用所有可能的功能,直到找到导致错误的原因,然后努力解决该特定问题:)
  • 当您部署到 heroku 时,它是否会在尝试将资产预编译为部署的一部分时输出任何错误或消息?您的仓库中是否存在“/public/assets/manifest.yml”?如果是这样,heroku 将假定资产已经被编译。

标签: ruby-on-rails twitter-bootstrap heroku


【解决方案1】:

我也遇到过同样的问题。实际上 gem 会发生冲突。这里'rufus-scheduler' gem 是罪魁祸首。尝试删除 gem 并部署。

接下来你可以试试这个

task :precompile, :roles => :web, :except => { :no_release => true } do 
  run_locally("rm -rf public/assets/*") 
  run_locally("bundle exec rake assets:precompile") 
  servers = find_servers_for_task(current_task) 
  port_option = port ? " -e 'ssh -p #{port}' " : '' 
  servers.each do |server| 
    run_locally("rsync --recursive --times --rsh=ssh --compress -- 
    human-readable #{port_option} --progress public/assets #{user} @#{server}:         {shared_path}") 
  end 
end 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多