Heroku上的部署失败,PostgreSQL ActionView :: Template :: Error

时间:2017-03-16 08:30:41

标签: ruby-on-rails ruby postgresql heroku deployment

我有一个使用ruby on rails(不是我自己)的网站构建,我被要求在heroku上部署它。不幸的是,我在RoR方面不是很有经验。经过大量的追踪和错误,我得到了网站在ubuntu系统上本地工作(使用sqlite3数据库)。

但是当我在生产中使用postgreSQL将它部署到heroku时,会出现错误。我已经尝试迁移数据库(heroku run rake db:migrate)并重新启动它。我还检查了this,但不明白: - /。

命令heroku logs显示:

testWebsite@Mogli1:~/testWebsite_WORKING_LOCALLY$ heroku logs
2017-03-13T12:05:11.768568+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
2017-03-13T12:05:11.768568+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
2017-03-13T12:05:11.768569+00:00 app[web.1]:    bin/rails:8:in `require'
2017-03-13T12:05:11.768570+00:00 app[web.1]:    bin/rails:8:in `<main>'
2017-03-13T12:05:11.768638+00:00 app[web.1]: [2017-03-13 12:05:11] INFO  going to shutdown ...
2017-03-13T12:05:11.768687+00:00 app[web.1]: [2017-03-13 12:05:11] INFO  WEBrick::HTTPServer#start done.
2017-03-13T12:05:11.768708+00:00 app[web.1]: Exiting
2017-03-13T12:05:12.011907+00:00 heroku[web.1]: Process exited with status 143
2017-03-16T07:46:48.168709+00:00 heroku[run.9616]: Awaiting client
2017-03-16T07:46:48.193736+00:00 heroku[run.9616]: Starting process with command `bundle exec rake db:migrate`
2017-03-16T07:46:48.369528+00:00 heroku[run.9616]: State changed from starting to up
2017-03-16T07:46:55.628642+00:00 heroku[run.9616]: Process exited with status 0
2017-03-16T07:46:55.643311+00:00 heroku[run.9616]: State changed from up to complete
2017-03-16T07:49:17.009091+00:00 heroku[web.1]: Unidling
2017-03-16T07:49:17.009364+00:00 heroku[web.1]: State changed from down to starting
2017-03-16T07:49:29.129238+00:00 heroku[web.1]: Starting process with command `bundle exec rails s -p 18792`
2017-03-16T07:49:37.584645+00:00 heroku[web.1]: State changed from starting to up
2017-03-16T07:49:37.201239+00:00 app[web.1]: [2017-03-16 07:49:37] INFO  WEBrick 1.3.1
2017-03-16T07:49:37.201265+00:00 app[web.1]: [2017-03-16 07:49:37] INFO  ruby 2.2.3 (2015-08-18) [x86_64-linux]
2017-03-16T07:49:37.201662+00:00 app[web.1]: [2017-03-16 07:49:37] INFO  WEBrick::HTTPServer#start: pid=4 port=18792
2017-03-16T07:49:39.088134+00:00 app[web.1]: => Booting WEBrick
2017-03-16T07:49:39.088147+00:00 app[web.1]: => Rails 4.2.4 application starting in production on http://0.0.0.0:18792
2017-03-16T07:49:39.088148+00:00 app[web.1]: => Run `rails server -h` for more startup options
2017-03-16T07:49:39.088148+00:00 app[web.1]: => Ctrl-C to shutdown server
2017-03-16T07:49:39.088149+00:00 app[web.1]: Started GET "/" for 195.37.177.70 at 2017-03-16 07:49:39 +0000
2017-03-16T07:49:39.260787+00:00 app[web.1]: Processing by HomePagesController#home_page_view as HTML
2017-03-16T07:49:39.566106+00:00 app[web.1]:   HomePage Load (14.0ms)  SELECT  "home_pages".* FROM "home_pages"  ORDER BY "home_pages"."id" ASC LIMIT 1
2017-03-16T07:49:39.673952+00:00 app[web.1]:   Slide Load (14.2ms)  SELECT "slides".* FROM "slides" WHERE (active = 't')  ORDER BY "slides"."viewing_index" ASC
2017-03-16T07:49:39.683330+00:00 app[web.1]:    (1.6ms)  SELECT COUNT(*) FROM "slides" WHERE (active = 't')
2017-03-16T07:49:39.686623+00:00 app[web.1]:   Rendered home_pages/home_page_view.html.haml within layouts/application (106.1ms)
2017-03-16T07:49:39.686848+00:00 app[web.1]: Completed 500 Internal Server Error in 426ms (ActiveRecord: 77.7ms)
2017-03-16T07:49:39.700715+00:00 app[web.1]: 
2017-03-16T07:49:39.700718+00:00 app[web.1]: ActionView::Template::Error (undefined method `testWebsite_de' for nil:NilClass):
2017-03-16T07:49:39.700719+00:00 app[web.1]:     39: .container#content
2017-03-16T07:49:39.700719+00:00 app[web.1]:     40:   .testWebsite-short
2017-03-16T07:49:39.700720+00:00 app[web.1]:     41:     -if I18n.locale == :de
2017-03-16T07:49:39.700721+00:00 app[web.1]:     42:       = @home_page.testWebsite_de.html_safe
2017-03-16T07:49:39.700722+00:00 app[web.1]:     43:     -if I18n.locale == :en
2017-03-16T07:49:39.700722+00:00 app[web.1]:     44:       = @home_page.testWebsite_en.html_safe
2017-03-16T07:49:39.700723+00:00 app[web.1]:     45: .teasers
2017-03-16T07:49:39.700724+00:00 app[web.1]:   app/views/home_pages/home_page_view.html.haml:42:in `_app_views_home_pages_home_page_view_html_haml___1156244683519038980_69885836641300'
2017-03-16T07:49:39.700725+00:00 app[web.1]: 
2017-03-16T07:49:39.700725+00:00 app[web.1]: 
2017-03-16T07:49:39.695715+00:00 heroku[router]: at=info method=GET path="/" host=limitless-forest-98133.herokuapp.com request_id=cfc6c015-f0f4-4b0f-af7a-5061ab3ea342 fwd="195.37.177.70" dyno=web.1 connect=0ms service=621ms status=500 bytes=1754 protocol=http
2017-03-16T07:49:39.979040+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=limitless-forest-98133.herokuapp.com request_id=caf0eb1c-bf56-4db5-b086-aff699644d51 fwd="195.37.177.70" dyno=web.1 connect=0ms service=17ms status=200 bytes=228 protocol=http
2017-03-16T07:52:18.105596+00:00 heroku[run.1897]: State changed from starting to up
2017-03-16T07:52:18.081549+00:00 heroku[run.1897]: Awaiting client
2017-03-16T07:52:18.168375+00:00 heroku[run.1897]: Starting process with command `bundle exec rake db:migrate`
2017-03-16T07:52:26.295869+00:00 heroku[run.1897]: State changed from up to complete
2017-03-16T07:52:26.254496+00:00 heroku[run.1897]: Process exited with status 0
2017-03-16T07:52:47.933811+00:00 heroku[web.1]: Restarting
2017-03-16T07:52:47.934413+00:00 heroku[web.1]: State changed from up to starting
2017-03-16T07:52:48.597708+00:00 app[web.1]: [2017-03-16 07:52:48] FATAL SignalException: SIGTERM
2017-03-16T07:52:48.597722+00:00 app[web.1]:    /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:174:in `select'
2017-03-16T07:52:48.597724+00:00 app[web.1]:    /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:174:in `block in start'
2017-03-16T07:52:48.597724+00:00 app[web.1]:    /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:32:in `start'
2017-03-16T07:52:48.597725+00:00 app[web.1]:    /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:162:in `start'
2017-03-16T07:52:48.597726+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:34:in `run'
2017-03-16T07:52:48.597726+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
2017-03-16T07:52:48.597727+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
2017-03-16T07:52:48.597728+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
2017-03-16T07:52:48.597729+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
2017-03-16T07:52:48.597729+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
2017-03-16T07:52:48.597730+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
2017-03-16T07:52:48.597731+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
2017-03-16T07:52:48.597732+00:00 app[web.1]:    bin/rails:8:in `require'
2017-03-16T07:52:48.597732+00:00 app[web.1]:    bin/rails:8:in `<main>'
2017-03-16T07:52:48.597819+00:00 app[web.1]: [2017-03-16 07:52:48] INFO  going to shutdown ...
2017-03-16T07:52:48.597876+00:00 app[web.1]: [2017-03-16 07:52:48] INFO  WEBrick::HTTPServer#start done.
2017-03-16T07:52:48.597907+00:00 app[web.1]: Exiting
2017-03-16T07:52:48.587611+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-03-16T07:52:48.803805+00:00 heroku[web.1]: Process exited with status 143
2017-03-16T07:52:58.894196+00:00 heroku[web.1]: Starting process with command `bundle exec rails s -p 6725`
2017-03-16T07:53:05.878954+00:00 app[web.1]: [2017-03-16 07:53:05] INFO  WEBrick 1.3.1
2017-03-16T07:53:05.878982+00:00 app[web.1]: [2017-03-16 07:53:05] INFO  ruby 2.2.3 (2015-08-18) [x86_64-linux]
2017-03-16T07:53:05.879354+00:00 app[web.1]: [2017-03-16 07:53:05] INFO  WEBrick::HTTPServer#start: pid=4 port=6725
2017-03-16T07:53:06.466569+00:00 heroku[web.1]: State changed from starting to up
2017-03-16T07:53:07.473807+00:00 app[web.1]: => Booting WEBrick
2017-03-16T07:53:07.473817+00:00 app[web.1]: => Rails 4.2.4 application starting in production on http://0.0.0.0:6725
2017-03-16T07:53:07.473818+00:00 app[web.1]: => Run `rails server -h` for more startup options
2017-03-16T07:53:07.473819+00:00 app[web.1]: => Ctrl-C to shutdown server
2017-03-16T07:53:07.473820+00:00 app[web.1]: Started GET "/" for 195.37.177.70 at 2017-03-16 07:53:07 +0000
2017-03-16T07:53:07.565021+00:00 app[web.1]: Processing by HomePagesController#home_page_view as HTML
2017-03-16T07:53:07.678903+00:00 app[web.1]:   Slide Load (1.4ms)  SELECT "slides".* FROM "slides" WHERE (active = 't')  ORDER BY "slides"."viewing_index" ASC
2017-03-16T07:53:07.684860+00:00 app[web.1]:    (0.9ms)  SELECT COUNT(*) FROM "slides" WHERE (active = 't')
2017-03-16T07:53:07.647395+00:00 app[web.1]:   HomePage Load (2.8ms)  SELECT  "home_pages".* FROM "home_pages"  ORDER BY "home_pages"."id" ASC LIMIT 1
2017-03-16T07:53:07.688874+00:00 app[web.1]: Completed 500 Internal Server Error in 124ms (ActiveRecord: 23.6ms)
2017-03-16T07:53:07.692956+00:00 app[web.1]: 
2017-03-16T07:53:07.692959+00:00 app[web.1]: ActionView::Template::Error (undefined method `testWebsite_de' for nil:NilClass):
2017-03-16T07:53:07.692960+00:00 app[web.1]:     39: .container#content
2017-03-16T07:53:07.692961+00:00 app[web.1]:     40:   .testWebsite-short
2017-03-16T07:53:07.692962+00:00 app[web.1]:     41:     -if I18n.locale == :de
2017-03-16T07:53:07.687979+00:00 app[web.1]:   Rendered home_pages/home_page_view.html.haml within layouts/application (31.4ms)
2017-03-16T07:53:07.692963+00:00 app[web.1]:     43:     -if I18n.locale == :en
2017-03-16T07:53:07.692962+00:00 app[web.1]:     42:       = @home_page.testWebsite_de.html_safe
2017-03-16T07:53:07.692964+00:00 app[web.1]:     44:       = @home_page.testWebsite_en.html_safe
2017-03-16T07:53:07.692968+00:00 app[web.1]:   app/views/home_pages/home_page_view.html.haml:42:in `_app_views_home_pages_home_page_view_html_haml___3877761630422882463_69824471651020'
2017-03-16T07:53:07.692969+00:00 app[web.1]: 
2017-03-16T07:53:07.692970+00:00 app[web.1]: 
2017-03-16T07:53:07.692964+00:00 app[web.1]:     45: .teasers
2017-03-16T07:53:07.694524+00:00 heroku[router]: at=info method=GET path="/" host=limitless-forest-98133.herokuapp.com request_id=2b456a65-b611-4f75-8b51-8fc9c445c495 fwd="195.37.177.70" dyno=web.1 connect=1ms service=231ms status=500 bytes=1754 protocol=http

任何人都可以给我一个提示或解释什么错误,因为我真的不明白这个?这是源代码的问题还是在部署过程中我错了?

由于 添

2 个答案:

答案 0 :(得分:1)

app/views/home_pages/home_page_view.html.haml

@home_page没有价值,变量获得nil值,因此您无法从testWebsite_de变量获得@home_page

您可以使用

避免错误
@home_page.try(:testWebsite_de).try(:html_safe)

答案 1 :(得分:1)

检查您的错误消息,即

ActionView::Template::Error (undefined method `testWebsite_de' for nil:NilClass):

在文件app / views / home_pages / home_page_view.html.haml:42

第42行,即

@home_page.testWebsite_de.html_safe

此处@home_page为nil,因此请使用以下代码进行更正:

@home_page.try(:testWebsite_de).try(:html_safe)

OR

@home_page.testWebsite_de.html_safe unless @home_page.nil?