2012-09-02 128 views
1

過去幾個晚上我一直在將我的第一個rails應用程序部署到heroku,並且一直在努力弄清楚如何解決這個問題。調試Heroku部署(500錯誤)

我使用Michael Hartl的教程(http://ruby.railstutorial.org/chapters/beginning#sec-deploying)來確保我在Cedar Stack上設置了我的應用程序。

根據Heroku教程,我使用「瘦」作爲服務器。

我讀了一堆的職位,並使用預編譯我的資產:

的Heroku運行包的exec耙資產:預編譯 捆綁高管耙資產:預編譯

我也遷移我的數據庫。

我的應用程序在我的本地主機上工作。

這裏是我的Gemfile:

source 'https://rubygems.org' 

gem 'rails', '3.2.8' 
gem 'bootstrap-sass', '2.0.0' 
gem 'bcrypt-ruby' 
gem 'thin' 

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

group :development do 
    gem 'sqlite3' 
end 

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

group :production do 
    gem 'pg' 
end 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
    # gem 'therubyracer', :platforms => :ruby 

    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 

group :test do 
    gem 'capybara' 
    gem 'factory_girl_rails' 
end 

這裏是我的Heroku的日誌

2012-09-02T01:56:17+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 
2012-09-02T01:56:20+00:00 app[web.1]: => Booting Thin 
2012-09-02T01:56:20+00:00 app[web.1]: => Rails 3.2.8 application starting in production on http://0.0.0.0:50510 
2012-09-02T01:56:20+00:00 app[web.1]: => Call with -d to detach 
2012-09-02T01:56:20+00:00 app[web.1]: => Ctrl-C to shutdown server 
2012-09-02T01:56:20+00:00 app[web.1]: Connecting to database specified by DATABASE_URL 
2012-09-02T01:56:21+00:00 app[web.1]: >> Thin web server (v1.4.1 codename Chromeo) 
2012-09-02T01:56:21+00:00 app[web.1]: >> Maximum connections set to 1024 
2012-09-02T01:56:21+00:00 app[web.1]: >> Listening on 0.0.0.0:50510, CTRL+C to stop 
2012-09-02T01:56:21+00:00 heroku[web.1]: State changed from starting to up 
2012-09-02T01:56:23+00:00 app[web.1]: 
2012-09-02T01:56:23+00:00 app[web.1]: 
2012-09-02T01:56:23+00:00 app[web.1]: Started GET "/" for 108.210.1.241 at 2012-09-02 01:56:23 +0000 
2012-09-02T01:56:23+00:00 app[web.1]: Processing by StaticPagesController#home as HTML 
2012-09-02T01:56:23+00:00 app[web.1]: Rendered static_pages/home.html.erb within layouts/application (14.9ms) 
2012-09-02T01:56:23+00:00 app[web.1]: Completed 500 Internal Server Error in 103ms 
2012-09-02T01:56:23+00:00 app[web.1]: ActionView::Template::Error (screen.css isn't precompiled): 
2012-09-02T01:56:23+00:00 app[web.1]: 
2012-09-02T01:56:23+00:00 app[web.1]:  2: <html> 
2012-09-02T01:56:23+00:00 app[web.1]:  3: <head> 
2012-09-02T01:56:23+00:00 heroku[router]: GET morning-inlet-9513.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=262ms status=500 bytes=643 
2012-09-02T01:56:23+00:00 app[web.1]:  4: <title>GabisBag</title> 
2012-09-02T01:56:23+00:00 app[web.1]: 
2012-09-02T01:56:23+00:00 app[web.1]:  5: <%= stylesheet_link_tag "screen", :media => "screen" %> 
2012-09-02T01:56:23+00:00 app[web.1]: 
2012-09-02T01:56:23+00:00 app[web.1]: app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__1090905269972481286_30934000' 
2012-09-02T01:56:23+00:00 app[web.1]:  6: <%= stylesheet_link_tag "landing_pages", :media => "screen" %> 
2012-09-02T01:56:23+00:00 app[web.1]:  7: <%= javascript_include_tag "application" %> 
2012-09-02T01:56:23+00:00 app[web.1]:  8: <%= csrf_meta_tags %> 
2012-09-02T02:05:54+00:00 heroku[api]: Starting process with command `bundle exec rake assets:precompile` by [email protected] 
2012-09-02T02:05:57+00:00 heroku[run.1]: Awaiting client 
2012-09-02T02:05:57+00:00 heroku[run.1]: Starting process with command `bundle exec rake assets:precompile` 
2012-09-02T02:05:58+00:00 heroku[run.1]: State changed from starting to up 
2012-09-02T02:06:14+00:00 heroku[run.1]: Client connection closed. Sending SIGHUP to all processes 
2012-09-02T02:06:15+00:00 heroku[run.1]: Process exited with status 0 
2012-09-02T02:06:15+00:00 heroku[run.1]: State changed from up to complete 
2012-09-02T02:08:22+00:00 heroku[slugc]: Slug compilation started 
2012-09-02T02:08:37+00:00 heroku[api]: D 
eploy 6817a8e by [email protected] 
2012-09-02T02:08:37+00:00 heroku[api]: Release v8 created by [email protected] 
2012-09-02T02:08:38+00:00 heroku[web.1]: State changed from up to starting 
2012-09-02T02:08:38+00:00 heroku[slugc]: Slug compilation finished 
2012-09-02T02:08:40+00:00 heroku[web.1]: Starting process with command `bundle exec rails server thin -p 42652 -e production` 
2012-09-02T02:08:41+00:00 heroku[web.1]: Stopping all processes with SIGTERM 
2012-09-02T02:08:41+00:00 app[web.1]: Exiting 
2012-09-02T02:08:42+00:00 heroku[web.1]: Process exited with status 0 
2012-09-02T02:08:44+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 
2012-09-02T02:08:44+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 
2012-09-02T02:08:47+00:00 app[web.1]: => Booting Thin 
2012-09-02T02:08:47+00:00 app[web.1]: => Rails 3.2.8 application starting in production on http://0.0.0.0:42652 
2012-09-02T02:08:47+00:00 app[web.1]: => Call with -d to detach 
2012-09-02T02:08:47+00:00 app[web.1]: => Ctrl-C to shutdown server 
2012-09-02T02:08:47+00:00 app[web.1]: Connecting to database specified by DATABASE_URL 
2012-09-02T02:08:48+00:00 app[web.1]: >> Thin web server (v1.4.1 codename Chromeo) 
2012-09-02T02:08:48+00:00 app[web.1]: >> Maximum connections set to 1024 
2012-09-02T02:08:48+00:00 app[web.1]: >> Listening on 0.0.0.0:42652, CTRL+C to stop 
2012-09-02T02:08:49+00:00 heroku[web.1]: State changed from starting to up 
2012-09-02T02:08:50+00:00 app[web.1]: Started GET "/" for 108.210.1.241 at 2012-09-02 02:08:50 +0000 
2012-09-02T02:08:50+00:00 app[web.1]: 
2012-09-02T02:08:50+00:00 app[web.1]: 
2012-09-02T02:08:50+00:00 app[web.1]: Processing by StaticPagesController#home as HTML 
2012-09-02T02:08:50+00:00 app[web.1]: Rendered static_pages/home.html.erb within layouts/application (9.3ms) 
2012-09-02T02:08:50+00:00 app[web.1]: Completed 500 Internal Server Error in 77ms 
2012-09-02T02:08:50+00:00 app[web.1]: 
2012-09-02T02:08:50+00:00 app[web.1]: ActionView::Template::Error (screen.css isn't precompiled): 
2012-09-02T02:08:50+00:00 app[web.1]:  2: <html> 
2012-09-02T02:08:50+00:00 app[web.1]:  3: <head> 
2012-09-02T02:08:50+00:00 app[web.1]:  4: <title>GabisBag</title> 
2012-09-02T02:08:50+00:00 app[web.1]:  5: <%= stylesheet_link_tag "screen", :media => "screen" %> 
2012-09-02T02:08:50+00:00 app[web.1]:  6: <%= stylesheet_link_tag "landing_pages", :media => "screen" %> 
2012-09-02T02:08:50+00:00 app[web.1]:  7: <%= javascript_include_tag "application" %> 
2012-09-02T02:08:50+00:00 app[web.1]:  8: <%= csrf_meta_tags %> 
2012-09-02T02:08:50+00:00 app[web.1]: app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__3619394764979485472_40067220' 
2012-09-02T02:08:50+00:00 app[web.1]: 
2012-09-02T02:08:50+00:00 app[web.1]: 
2012-09-02T02:08:50+00:00 heroku[router]: GET morning-inlet-9513.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=221ms status=500 bytes=643 
2012-09-02T02:14:08+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by [email protected] 
2012-09-02T02:14:10+00:00 heroku[run.1]: Awaiting client 
2012-09-02T02:14:10+00:00 heroku[run.1]: Starting process with command `bundle exec rake db:migrate` 
2012-09-02T02:14:11+00:00 heroku[run.1]: State changed from starting to up 
2012-09-02T02:14:17+00:00 heroku[run.1]: Client connection closed. Sending SIGHUP to all processes 
2012-09-02T02:14:18+00:00 heroku[run.1]: Process exited with status 0 
2012-09-02T02:14:18+00:00 heroku[run.1]: State changed from up to complete 
2012-09-02T02:14:35+00:00 app[web.1]: 
2012-09-02T02:14:35+00:00 app[web.1]: Started GET "/" for 108.210.1.241 at 2012-09-02 02:14:35 +0000 
2012-09-02T02:14:35+00:00 app[web.1]: 
2012-09-02T02:14:35+00:00 app[web.1]: Processing by StaticPagesController#home as HTML 
2012-09-02T02:14:35+00:00 app[web.1]: Rendered static_pages/home.html.erb within layouts/application (0.5ms) 
2012-09-02T02:14:35+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms 
2012-09-02T02:14:35+00:00 app[web.1]: 
2012-09-02T02:14:35+00:00 app[web.1]: ActionView::Template::Error (screen.css isn't precompiled): 
2012-09-02T02:14:35+00:00 app[web.1]:  2: <html> 
2012-09-02T02:14:35+00:00 app[web.1]:  3: <head> 
2012-09-02T02:14:35+00:00 app[web.1]:  4: <title>GabisBag</title> 
2012-09-02T02:14:35+00:00 app[web.1]:  5: <%= stylesheet_link_tag "screen", :media => "screen" %> 
2012-09-02T02:14:35+00:00 app[web.1]:  6: <%= stylesheet_link_tag "landing_pages", :media => "screen" %> 
2012-09-02T02:14:35+00:00 app[web.1]:  7: <%= javascript_include_tag "application" %> 
2012-09-02T02:14:35+00:00 app[web.1]:  8: <%= csrf_meta_tags %> 
2012-09-02T02:14:35+00:00 app[web.1]: app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__3619394764979485472_40067220' 
2012-09-02T02:14:35+00:00 app[web.1]: 
2012-09-02T02:14:35+00:00 app[web.1]: 
2012-09-02T02:14:35+00:00 heroku[router]: GET morning-inlet-9513.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=11ms status=500 bytes=643 

回答

1

以下是我最終如何解決問題的方法。感謝那些在別處提到我的人,以便我可以將它們放在一起。

首先,我將Blueprint移動到了供應商目錄。我不認爲這對解決方案至關重要,但它感覺更清潔。

編譯問題:

這個線程:blueprint css rails 3.1 help是真的很有幫助。我發現Martin和Gary的回覆(第2和第3)比選定的回覆更有幫助。

爲什麼我在編譯(個人)時遇到問題,部分原因是我對Blueprint文件進行了一些編輯,這意味着他們需要在部署之前再次編譯。

此主題:rails 3.1.0 ActionView::Template::Error (application.css isn't precompiled)在這方面很有幫助。基本上,在上傳到heroku之前,運行「Bundle exec rake assets:precompile」。上傳後我還運行「heroku run rake assets:precompile」。

我是怎麼擺脫URL的斜線在我的鏈接: 的網址是此代碼藍圖/ print.css的結果:

a:link, a:visited {background:transparent;font-weight:700;text-decoration:underline;} 
a:link:after, a:visited:after {content:" (" attr(href) ")";font-size:90%;} 

我解決了註釋掉的代碼問題。當然,在更改文件之後,您必須重新分配資源:再次預編譯。但是,這一切都工作!

2

這看起來像重要的部分:

ActionView::Template::Error (screen.css isn't precompiled): 

好像this thread將解決您的問題。

,因爲它說:

On heroku server (readonly filesystem), If you want runtime compilation of css (its not recommended but you can do it), make sure you have done settings like below - 

# inside config/application.rb 
config.assets.enabled = true 
config.assets.prefix = Rails.root.join('tmp/assets').to_s 

# If you are using sass then keep gem outside of asset group 
gem 'sass-rails', '3.1.4' 

# inside config/environments/production.rb 
config.assets.compile = true 
+0

感謝您的回覆!我昨晚看過那篇文章並試了一下。根據你的建議,我今天早上再試一次。仍然沒有工作。儘管如此,我還沒有嘗試過你在這裏提倡的運行時編譯方法,因爲我讀過的所有內容都表明這樣做會有相當大的性能損失。我錯了嗎? – jflores

+0

是的,有,但我找不到任何其他選項來解決您遇到的問題。但是,你可能會破壞一些東西。 –

1

我在這裏找到了答案:blueprint css rails 3.1 help

到目前爲止,我所知道的,這似乎是一個問題,使用Blueprint CSS框架。這就是說,其他兩個注意事項:

  1. 我註釋掉<%= stylesheet_link_tag 「畫面」,:媒體=> 「屏幕」 %>從我application.html.erb佈局文件的代碼。
  2. 我沒有安裝'rubyracer'gem。我安裝它,因爲它在引用的答案的配置文件中。我不知道它做了什麼。
  3. 無論我有鏈接,URL斜槓(「/」)現在都會再次顯示。我的預感是,它只是一些CSS文件中的東西,我不得不深入並進行調試。但是,首先我有stylesheet_link_tag事情的全部原因是因爲我試圖擺脫那些討厭的斜線。最終,我決定部署更重要。

希望這對別人有幫助!

+0

另外,我在本地預編譯所有東西(bundle exec rake assets:precompile)和heroku(heroku run bundle exec rake assets:預編譯) – jflores

+0

嗨,很高興它的工作!如果此答案解決了您的問題,則應點擊大號複選框將答案標記爲「已接受」。這有助於人們知道您的問題已得到解決:)請參閱[此常見問題解答條目](http://meta.stackexchange.com/a/5235/189918)。歡迎來到堆棧溢出! – culix

+0

謝謝你提醒我!這個解決方案實際上並不完美,因爲我仍然有這些斜槓。但是,我最終弄清楚了,所以我發佈了一個解決這兩個問題(編譯問題和URL /斜槓問題)的答案。 – jflores