1

在将我的 Rails 应用程序部署到生产环境时,我遇到了一个从未遇到过的奇怪问题。

我跑:

bundle exec rake assets:precompile

这是输出:

/home/ubuntu/.rvm/rubies/ruby-2.0.0-p0/bin/ruby /home/ubuntu/.rvm/gems/ruby-2.0.0-p0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p0/bin/ruby /home/ubuntu/.rvm/gems/ruby-2.0.0-p0/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets

这是我的应用程序/资产/javascripts/application.js:

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require twitter/bootstrap
//= require_tree .

这是我的 app/assets/stylesheets/application.css:

/*
 *= require_self
 *= require jquery.ui.all
 *= require_tree . 
*/

预编译后,这是我的 public/assets/application-946a5a61f067fe19fe65ffd12f8c4a20.js

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require twitter/bootstrap
//= require_tree .

所以它与原始文件完全相同。

而 public/assets/application-df7525e917401704ef453cb56bf16697.css 是一个空文件。

这是我的 Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.1'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'settingslogic'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'json'
gem 'will_paginate', '~>3.0.pre2'
gem 'friendly_id', '~> 4.0.0.beta14'
gem 'rails3-jquery-autocomplete'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'paperclip', '~> 3.0'
gem 'public_activity'
gem 'rails-timeago'
gem 'therubyracer', :require => 'v8'
gem 'less-rails'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier', '>= 1.0.3'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
end

和 config/environments/production.rb:

Yupp::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 = false

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

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false

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

  #config.assets.initialize_on_precompile = false

#...
end

任何方向将不胜感激。

4

2 回答 2

3

什么为我解决了这个问题:

  • 在 Gemfile 中设置最后一个 rails 版本(目前为 3.2.14)

  • bundle update

  • bundle install

  • 重启应用touch tmp/restart.txt

于 2013-09-14T15:58:50.163 回答
2

我花了 2 个小时,然后我找到了https://github.com/sstephenson/sprockets/issues/352

我尝试将 ruby​​ 降级到 1.9.3 并进行预编译,然后将编译后的文件添加到 repo.. 这不是我想要的,但它可以工作..

更新:您使用的是什么版本的导轨?我正在使用 3.2.2 有这样的问题。3.2.13 工作正常(使用 ruby​​ 2.0)。

于 2013-06-27T01:06:56.133 回答