1

我在使用 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 assets:precompile 时,我遇到了问题:

/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'

想法将不胜感激。先感谢您。

4

1 回答 1

1

您好,您可以将 gem 放在资产路径之外:

gem "haml"

gem 'haml-rails'

并取消注释asset_path

并捆绑安装

或者你可以参考:

如何让 Haml 与 Rails 一起工作?

于 2013-04-17T05:46:38.253 回答