耙资产:预编译停滞 [英] rake assets:precompile stuck

查看:89
本文介绍了耙资产:预编译停滞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前我发现jquery日历不适用于我的部署站点(heroku)。在挖掘问题我注意到,我的开发服务器上的网站的源有大约100个脚本标签与bootstrap(我使用twitter引导程序的CSS),但在prod服务器上。我有4个脚本标签。在搜索时,我发现我应该在资产管道的rails控制台上运行 rake assets:precompile 。但是运行时间非常长,上次花了6个小时,我不得不放弃它。

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

  ProductRecall :: Application.configure do 
#此处指定的设置优先于config / application.rb中的设置

#代码不会在请求之间重新加载$ ​​b $ b config.cache_classes = true

#完全错误报告被禁用且缓存已打开
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

#禁用Rails的静态资产服务器(Apache或nginx已经这样做)
config.serve_static_assets = true

#压缩JavaScript和CSS
config.assets.compress = true

#如果预编译的资产不存在,则不要回退到资产管道
config.assets.compile = true

#为资产URL生成摘要
config.assets .digest = true



#指定您的服务器用于发送文件的标题
#config.action_dispatch.x_sendfile_header =X-Sendfile#for apache
config.action_dispatch.x_sendfile_header ='X-Accel-Redirect'#for nginx

#强制所有对应用程序的访问通过SSL,使用Strict-Transport-Security,并使用安全cookie。
config.force_ssl = true

#为I18n启用语言环境回退(使查找任何语言环境回落到
#无法找到翻译时的I18n.default_locale)
config.i18n.fallbacks = true

#将弃用声明发送给已注册的侦听器
config.active_support.deprecation =:notify

#记录查询计划对于比这更多的查询(在SQLite,MySQL和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__)

#选择你想要的框架:
需要active_record / railtie
需要action_controller / railtie
需要action_mailer / railtie
需要active_resource / railtie
要求链轮/ railtie
#requirerails / test_unit / railtie

如果已定义?(Bundler)
#如果您在部署到生产前预编译资产,请使用以下行
Bundler。 require(* Rails.groups(:assets => %w(开发测试)))
#如果你希望你的资产在生产中被懒惰地编译,使用这行
Bundler.require(:default,:assets,Rails.env)
end

模块ProductRecall
类应用程序< Rails :: Application

#配置Ruby 1.9模板中使用的默认编码。
config.encoding =utf-8

#配置将从日志文件中过滤的敏感参数。
config.filter_parameters + = [:password]

#在JSON中启用转义HTML。
config.active_support.escape_html_entities_in_json = true

#强制执行批量分配的白名单模式。
#这将为您的应用中的所有模型
#创建一个可用于批量分配的空白白名单。因此,您的模型需要使用attr_accessible或attr_protected声明将可访问的
#参数明确列入白名单或黑名单。
config.active_record.whitelist_attributes = true

#启用资产管道
config.assets.enabled = true

#您的资产版本,更改如果你想过期所有的资产
config.assets.version ='1.0'
config.action_mailer.default_url_options = {host:'localhost:3000'}
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'
gemgoogle_visualr,〜> 2.1.0
gem'twitter-bootstrap-rails'
gemgaletahub-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天以来我一直没有线索

解决方案

我也面临同样的问题。其实宝石会发生冲突。这里的'rufus-scheduler'宝石是罪魁祸首。尝试删除宝石并部署。



接下来您可以试试这个

  task:precompile,:roles => :web,:except => {:no_release => true} 
run_locally(rm -rf public / assets / *)
run_locally(bundle exec rake assets:precompile)
servers = find_servers_for_task(current_task)
port_option =端口? -e'ssh -p#{port}':''
servers.each do | server |
run_locally(rsync --recursive --times --rsh = ssh --compress -
人可读#{port_option} --progress public / assets#{user} @#{server} :{shared_pa​​th})
结束
结束


couple of days ago i noticed that jquery calendar is not working on my deployment site(heroku). on digging out the problem i noticed that source of site on my dev server has some 100 script tags related to bootstrap(i am using twitter bootstrap css) but on prod server. i have 4 script tags. on searching i found that i should run rake assets:precompile on my rails console fo asset pipeline. but while running it is taking terribly long time, last time it took 6 hours and i had to abort it.

referring to many sites and post, i found that i should change config.serve_static_assetsto true and config.assets.compile to true. but problem is still there. i also tried to remove jquery-rails/jquery-ui-rails from gembut problem is still there. here is my 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

my config/application.rb looks like this

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

here is my Gem file:

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

plz let me know what is wrong here. as i am terribly stuck with no clue since 2 days

解决方案

I had also faced the same problem. Actually gem gets conflict. Here 'rufus-scheduler' gem is the culprit. Try to remove the gem and deploy.

Next you can try this

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 

这篇关于耙资产:预编译停滞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆