资产管道在rails生产环境中不起作用

时间:2013-04-17 05:18:23

标签: ruby-on-rails capistrano asset-pipeline bundler unicorn

我在使用Rails部署到VPS时遇到问题。我的应用程序在开发环境中运行良好,但是当我使用Capistrano进行生产时,我遇到了问题。

我正在使用独角兽,rails 3.2.13和ruby 1.9.3

我遇到的问题是当我访问我的生产网站时,我收到了“模板丢失”错误:

Template is missing

Missing template site/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :haml]}. Searched in: * "/home/deployer/apps/my-app/releases/20130417030832/app/views" * "/home/deployer/apps/my-app/shared/bundle/ruby/1.9.1/gems/devise-2.2.3/app/views" * "/home/deployer/apps/my-app/shared/bundle/ruby/1.9.1/bundler/gems/piggybak_paypal-b892954868c7/app/views" * "/home/deployer/apps/my-app/shared/bundle/ruby/1.9.1/gems/piggybak_variants-0.0.15/app/views" * "/home/deployer/apps/my-app/shared/bundle/ruby/1.9.1/gems/piggybak-0.6.28/app/views" * "/home/deployer/apps/my-app/shared/bundle/ruby/1.9.1/bundler/gems/rails_admin-b8465f738261/app/views" * "/home/deployer/apps/my-app/shared/bundle/ruby/1.9.1/gems/kaminari-0.14.1/app/views"

所以,我认为这可能是资产预编译问题。当我运行rake资产:在我的本地开发环境中进行预编译时,我遇到了问题:

/Users/ac/.rvm/rubies/ruby-1.9.3-p392/bin/ruby /Users/ac/.rvm/gems/ruby-1.9.3-p392/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
FATAL:  password authentication failed for user "deployer"
/Users/ac/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize'
/Users/ac/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `new'
/Users/ac/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `connect'
...

deployer是我的生产数据库用户的名称,位于生产命名空间下的database.yml中。我不确定为什么要尝试加载它。我肯定在开发模式下运行服务器。

我还在生产服务器上的unicorn.log文件中注明了这一点:

I, [2013-04-17T04:44:46.626587 #16199]  INFO -- : executing ["/home/deployer/apps/my-app/shared/bundle/ruby/1.9.1/bin/unicorn", "-D", "-c", "/home/deployer/apps/my-app/current/config/unicorn.rb", "-E", "production", {12=>#<Kgio::UNIXServer:fd 12>}] (in /home/deployer/apps/my-app/releases/20130417044320)
I, [2013-04-17T04:44:46.627160 #16199]  INFO -- : forked child re-executing...
/home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler/definition.rb:16:in `build': /home/deployer/apps/my-app/releases/20130417020329/Gemfile not found (Bundler::GemfileNotFound)
  from /home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler.rb:148:in `definition'
  from /home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
  from /home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
  from /home/deployer/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  from /home/deployer/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
E, [2013-04-17T04:44:46.777335 #18166] ERROR -- : reaped #<Process::Status: pid 16199 exit 1> exec()-ed

这是我的宝石文件:

source 'https://rubygems.org'

gem 'rails', '3.2.13'

gem 'pg'

gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'

gem 'piggybak', '0.6.28'
gem "piggybak_variants", '0.0.15'
gem 'piggybak_paypal', :git => 'git://github.com/timmyc/piggybak_paypal.git'

gem 'devise'
gem "cancan"

gem 'countries', :require => 'iso3166'

gem "figaro"

gem 'redactor-rails'
gem "carrierwave"
gem 'rmagick', '2.13.2'
gem "mini_magick"
gem "fog", "~> 1.3.1"

gem 'turbolinks'

gem 'tire', '0.5.7' # elastic search

gem 'kaminari'

gem "friendly_id", "~> 4.0.9"
gem 'acts-as-taggable-on', '>= 2.3.1'
gem 'acts_as_list'
gem 'meta-tags', :require => 'meta_tags'


#group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'haml-rails'
  gem 'uglifier', '>= 1.0.3'
#end

group :development do
  gem 'bullet'
  gem 'meta_request'
end

gem 'jquery-rails'

gem "unicorn-rails"

gem 'capistrano'
gem 'rvm-capistrano'

我们将非常感谢您的想法。提前谢谢。

1 个答案:

答案 0 :(得分:1)

你好,你可以把宝石放在资产路径之外:

gem "haml"

gem 'haml-rails'

并取消注释asset_path

并捆绑安装

或者你可以参考:

How do I get Haml to work with Rails?