首页 > 解决方案 > Rails 5 应用程序 NoMethodError(nil:NilClass 的未定义方法 `take')部署到 Heroku,即使应用程序成功启动并在本地运行

问题描述

请帮忙。我试图部署,但我不断收到此错误:

Ruby 2.5.1、Rails 5.2.1

NoMethodError (undefined method取'为 nil:NilClass)`

这是我在运行 heroku logs --tail 后得到的结果

2018-10-11T13:03:05.246461+00:00 app[api]: Deploy 963768cb by user davistyrant@gmail.com
2018-10-11T13:03:08.000000+00:00 app[api]: Build succeeded
2018-10-11T13:03:26.035893+00:00 heroku[web.1]: State changed from starting to up
2018-10-11T13:06:13.341881+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=b5d4a234-a19c-4bee-82b3-f62d476e2e4f fwd="107.208.176.45" dyno=web.1 connect=0ms service=135ms status=500 bytes=1827 protocol=https
2018-10-11T13:06:13.489601+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=1b04c8c6-4f86-4218-897c-bf207d88429e fwd="107.208.176.45" dyno=web.1 connect=0ms service=1ms status=200 bytes=143 protocol=https
2018-10-11T13:06:13.216901+00:00 app[web.1]: => Booting Puma
2018-10-11T13:06:13.216915+00:00 app[web.1]: => Rails 5.2.1 application starting in production
2018-10-11T13:06:13.216916+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-10-11T13:06:13.216919+00:00 app[web.1]: Puma starting in single mode...
2018-10-11T13:06:13.216921+00:00 app[web.1]: * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
2018-10-11T13:06:13.216923+00:00 app[web.1]: * Min threads: 5, max threads: 5
2018-10-11T13:06:13.216925+00:00 app[web.1]: * Environment: production
2018-10-11T13:06:13.216926+00:00 app[web.1]: * Listening on tcp://0.0.0.0:50580
2018-10-11T13:06:13.216928+00:00 app[web.1]: Use Ctrl-C to stop
2018-10-11T13:06:13.216942+00:00 app[web.1]: I, [2018-10-11T13:06:13.216751 #4]  INFO -- : [b5d4a234-a19c-4bee-82b3-f62d476e2e4f] Started GET "/" for 107.208.176.45 at 2018-10-11 13:06:13 +0000
2018-10-11T13:06:13.233800+00:00 app[web.1]: I, [2018-10-11T13:06:13.233383 #4]  INFO -- : [b5d4a234-a19c-4bee-82b3-f62d476e2e4f] Processing by WelcomeController#index as HTML
2018-10-11T13:06:13.330720+00:00 app[web.1]: I, [2018-10-11T13:06:13.330083 #4]  INFO -- : [b5d4a234-a19c-4bee-82b3-f62d476e2e4f] Completed 500 Internal Server Error in 96ms
2018-10-11T13:06:13.333178+00:00 app[web.1]: F, [2018-10-11T13:06:13.332386 #4] FATAL -- : [b5d4a234-a19c-4bee-82b3-f62d476e2e4f]
2018-10-11T13:06:13.333310+00:00 app[web.1]: F, [2018-10-11T13:06:13.333238 #4] FATAL -- : [b5d4a234-a19c-4bee-82b3-f62d476e2e4f] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T13:06:13.333653+00:00 app[web.1]: F, [2018-10-11T13:06:13.333577 #4] FATAL -- : [b5d4a234-a19c-4bee-82b3-f62d476e2e4f] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T13:06:13.333411+00:00 app[web.1]: F, [2018-10-11T13:06:13.333339 #4] FATAL -- : [b5d4a234-a19c-4bee-82b3-f62d476e2e4f]
2018-10-11T13:09:19.127834+00:00 app[api]: Starting process with command `rails console` by user davistyrant@gmail.com
2018-10-11T13:09:24.050501+00:00 heroku[run.4443]: Awaiting client
2018-10-11T13:09:24.081061+00:00 heroku[run.4443]: Starting process with command `rails console`
2018-10-11T13:09:24.280826+00:00 heroku[run.4443]: State changed from starting to up
2018-10-11T13:10:55.522089+00:00 heroku[run.4443]: State changed from up to complete
2018-10-11T13:10:55.483371+00:00 heroku[run.4443]: Process exited with status 0
2018-10-11T13:11:13.864425+00:00 heroku[web.1]: Restarting
2018-10-11T13:11:13.865182+00:00 heroku[web.1]: State changed from up to starting
2018-10-11T13:11:15.168348+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2018-10-11T13:11:15.185010+00:00 app[web.1]: === puma shutdown: 2018-10-11 13:11:15 +0000 ===
2018-10-11T13:11:15.185017+00:00 app[web.1]: - Goodbye!
2018-10-11T13:11:15.185137+00:00 app[web.1]: Exiting
2018-10-11T13:11:15.149622+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-10-11T13:11:15.294776+00:00 heroku[web.1]: Process exited with status 143
2018-10-11T13:11:19.511046+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 56912 -e production`
2018-10-11T13:11:32.632444+00:00 heroku[web.1]: State changed from starting to up
2018-10-11T13:12:03.512111+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=236d4168-88a6-4bcc-95fb-612cedba6999 fwd="107.208.176.45" dyno=web.1 connect=1ms service=138ms status=500 bytes=1827 protocol=https
2018-10-11T13:12:03.377824+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-10-11T13:12:03.377826+00:00 app[web.1]: Puma starting in single mode...
2018-10-11T13:12:03.377827+00:00 app[web.1]: * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
2018-10-11T13:12:03.377805+00:00 app[web.1]: => Booting Puma
2018-10-11T13:12:03.377822+00:00 app[web.1]: => Rails 5.2.1 application starting in production
2018-10-11T13:12:03.377832+00:00 app[web.1]: * Listening on tcp://0.0.0.0:56912
2018-10-11T13:12:03.377834+00:00 app[web.1]: Use Ctrl-C to stop
2018-10-11T13:12:03.377829+00:00 app[web.1]: * Min threads: 5, max threads: 5
2018-10-11T13:12:03.509402+00:00 app[web.1]: F, [2018-10-11T13:12:03.509288 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999]
2018-10-11T13:12:03.509674+00:00 app[web.1]: F, [2018-10-11T13:12:03.509603 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999]
2018-10-11T13:12:03.509574+00:00 app[web.1]: F, [2018-10-11T13:12:03.509450 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T13:12:03.377831+00:00 app[web.1]: * Environment: production
2018-10-11T13:12:03.395400+00:00 app[web.1]: I, [2018-10-11T13:12:03.395269 #4]  INFO -- : [236d4168-88a6-4bcc-95fb-612cedba6999] Processing by WelcomeController#index as HTML
2018-10-11T13:12:03.508276+00:00 app[web.1]: I, [2018-10-11T13:12:03.508113 #4]  INFO -- : [236d4168-88a6-4bcc-95fb-612cedba6999] Completed 500 Internal Server Error in 112ms
2018-10-11T13:12:03.377845+00:00 app[web.1]: I, [2018-10-11T13:12:03.377672 #4]  INFO -- : [236d4168-88a6-4bcc-95fb-612cedba6999] Started GET "/" for 107.208.176.45 at 2018-10-11 13:12:03 +0000
2018-10-11T13:12:03.509854+00:00 app[web.1]: F, [2018-10-11T13:12:03.509752 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T13:12:03.941190+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=6e8c624c-0141-4da4-9dbc-426ca3099276 fwd="107.208.176.45" dyno=web.1 connect=1ms service=4ms status=200 bytes=143 protocol=https
2018-10-11T13:15:25.880221+00:00 heroku[web.1]: Restarting
2018-10-11T13:15:25.880730+00:00 heroku[web.1]: State changed from up to starting
2018-10-11T13:15:26.736019+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-10-11T13:15:26.814218+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2018-10-11T13:15:26.834175+00:00 app[web.1]: === puma shutdown: 2018-10-11 13:15:26 +0000 ===
2018-10-11T13:15:26.834492+00:00 app[web.1]: Exiting
2018-10-11T13:15:26.834261+00:00 app[web.1]: - Goodbye!
2018-10-11T13:15:27.169490+00:00 heroku[web.1]: Process exited with status 143
2018-10-11T13:15:29.605096+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 29987 -e production`
2018-10-11T13:15:35.374170+00:00 heroku[web.1]: State changed from starting to up
2018-10-11T13:16:47.479481+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=ca9b9cf4-45bb-4139-8397-748a53ff1ecd fwd="107.208.176.45" dyno=web.1 connect=0ms service=60ms status=500 bytes=1827 protocol=https
2018-10-11T13:16:47.423357+00:00 app[web.1]: => Booting Puma
2018-10-11T13:16:47.423392+00:00 app[web.1]: => Rails 5.2.1 application starting in production
2018-10-11T13:16:47.423394+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-10-11T13:16:47.423399+00:00 app[web.1]: Puma starting in single mode...
2018-10-11T13:16:47.423401+00:00 app[web.1]: * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
2018-10-11T13:16:47.423407+00:00 app[web.1]: * Min threads: 5, max threads: 5
2018-10-11T13:16:47.423408+00:00 app[web.1]: * Environment: production
2018-10-11T13:16:47.423411+00:00 app[web.1]: Use Ctrl-C to stop
2018-10-11T13:16:47.423410+00:00 app[web.1]: * Listening on tcp://0.0.0.0:29987
2018-10-11T13:16:47.423419+00:00 app[web.1]: I, [2018-10-11T13:16:47.423133 #4]  INFO -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] Started GET "/" for 107.208.176.45 at 2018-10-11 13:16:47 +0000
2018-10-11T13:16:47.433037+00:00 app[web.1]: I, [2018-10-11T13:16:47.432896 #4]  INFO -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] Processing by WelcomeController#index as HTML
2018-10-11T13:16:47.477319+00:00 app[web.1]: I, [2018-10-11T13:16:47.477177 #4]  INFO -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] Completed 500 Internal Server Error in 39ms
2018-10-11T13:16:47.478108+00:00 app[web.1]: F, [2018-10-11T13:16:47.478014 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd]
2018-10-11T13:16:47.478185+00:00 app[web.1]: F, [2018-10-11T13:16:47.478103 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T13:16:47.478322+00:00 app[web.1]: F, [2018-10-11T13:16:47.478183 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd]
2018-10-11T13:16:47.478406+00:00 app[web.1]: F, [2018-10-11T13:16:47.478327 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T13:16:47.911583+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=d45521a1-be85-47f5-a36c-ffffcddbfe5a fwd="107.208.176.45" dyno=web.1 connect=0ms service=1ms status=304 bytes=48 protocol=https
2018-10-11T13:31:53.937375+00:00 app[web.1]: I, [2018-10-11T13:31:53.937211 #4]  INFO -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] Started GET "/" for 107.208.176.45 at 2018-10-11 13:31:53 +0000
2018-10-11T13:31:53.938482+00:00 app[web.1]: I, [2018-10-11T13:31:53.938396 #4]  INFO -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] Processing by WelcomeController#index as HTML
2018-10-11T13:31:53.965078+00:00 app[web.1]: I, [2018-10-11T13:31:53.964899 #4]  INFO -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] Completed 500 Internal Server Error in 26ms
2018-10-11T13:31:53.966246+00:00 app[web.1]: F, [2018-10-11T13:31:53.966126 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b]
2018-10-11T13:31:53.966365+00:00 app[web.1]: F, [2018-10-11T13:31:53.966277 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T13:31:53.966447+00:00 app[web.1]: F, [2018-10-11T13:31:53.966367 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b]
2018-10-11T13:31:53.966553+00:00 app[web.1]: F, [2018-10-11T13:31:53.966462 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T13:31:54.111275+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=ca2791a5-20a1-4232-9d7d-e22b54f5cef0 fwd="107.208.176.45" dyno=web.1 connect=1ms service=2ms status=200 bytes=143 protocol=https
2018-10-11T13:31:53.967004+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=bb6be014-e6b9-46da-88d4-1b3bec87236b fwd="107.208.176.45" dyno=web.1 connect=1ms service=33ms status=500 bytes=1827 protocol=https
2018-10-11T14:08:06.626516+00:00 heroku[web.1]: Idling
2018-10-11T14:08:06.627170+00:00 heroku[web.1]: State changed from up to down
2018-10-11T14:08:07.504722+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-10-11T14:08:07.522614+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2018-10-11T14:08:07.540228+00:00 app[web.1]: === puma shutdown: 2018-10-11 14:08:07 +0000 ===
2018-10-11T14:08:07.540234+00:00 app[web.1]: - Goodbye!
2018-10-11T14:08:07.541182+00:00 app[web.1]: Exiting
2018-10-11T14:08:07.697959+00:00 heroku[web.1]: Process exited with status 143
^C
*[test-bundler][~/Documents/certification-project/tellmetele]$ heroku restart           rvm:ruby-2.5.1 
Restarting dynos on ⬢ tellmetele... done
*[test-bundler][~/Documents/certification-project/tellmetele]$ heroku apps:info         rvm:ruby-2.5.1 
=== tellmetele
Addons:         heroku-postgresql:hobby-dev
Auto Cert Mgmt: false
Dynos:          web: 1
Git URL:        https://git.heroku.com/tellmetele.git
Owner:          davistyrant@gmail.com
Region:         us
Repo Size:      113 KB
Slug Size:      49 MB
Stack:          heroku-18
Web URL:        https://tellmetele.herokuapp.com/
*[test-bundler][~/Documents/certification-project/tellmetele]$ heroku logs --tail       rvm:ruby-2.5.1 
2018-10-11T13:09:19.127834+00:00 app[api]: Starting process with command `rails console` by user davistyrant@gmail.com
2018-10-11T13:09:24.050501+00:00 heroku[run.4443]: Awaiting client
2018-10-11T13:09:24.081061+00:00 heroku[run.4443]: Starting process with command `rails console`
2018-10-11T13:09:24.280826+00:00 heroku[run.4443]: State changed from starting to up
2018-10-11T13:10:55.522089+00:00 heroku[run.4443]: State changed from up to complete
2018-10-11T13:10:55.483371+00:00 heroku[run.4443]: Process exited with status 0
2018-10-11T13:11:13.864425+00:00 heroku[web.1]: Restarting
2018-10-11T13:11:13.865182+00:00 heroku[web.1]: State changed from up to starting
2018-10-11T13:11:15.168348+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2018-10-11T13:11:15.185010+00:00 app[web.1]: === puma shutdown: 2018-10-11 13:11:15 +0000 ===
2018-10-11T13:11:15.185017+00:00 app[web.1]: - Goodbye!
2018-10-11T13:11:15.185137+00:00 app[web.1]: Exiting
2018-10-11T13:11:15.149622+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-10-11T13:11:15.294776+00:00 heroku[web.1]: Process exited with status 143
2018-10-11T13:11:19.511046+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 56912 -e production`
2018-10-11T13:11:32.632444+00:00 heroku[web.1]: State changed from starting to up
2018-10-11T13:12:03.512111+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=236d4168-88a6-4bcc-95fb-612cedba6999 fwd="107.208.176.45" dyno=web.1 connect=1ms service=138ms status=500 bytes=1827 protocol=https
2018-10-11T13:12:03.377824+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-10-11T13:12:03.377826+00:00 app[web.1]: Puma starting in single mode...
2018-10-11T13:12:03.377827+00:00 app[web.1]: * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
2018-10-11T13:12:03.377805+00:00 app[web.1]: => Booting Puma
2018-10-11T13:12:03.377822+00:00 app[web.1]: => Rails 5.2.1 application starting in production
2018-10-11T13:12:03.377832+00:00 app[web.1]: * Listening on tcp://0.0.0.0:56912
2018-10-11T13:12:03.377834+00:00 app[web.1]: Use Ctrl-C to stop
2018-10-11T13:12:03.377829+00:00 app[web.1]: * Min threads: 5, max threads: 5
2018-10-11T13:12:03.509402+00:00 app[web.1]: F, [2018-10-11T13:12:03.509288 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999]
2018-10-11T13:12:03.509674+00:00 app[web.1]: F, [2018-10-11T13:12:03.509603 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999]
2018-10-11T13:12:03.509574+00:00 app[web.1]: F, [2018-10-11T13:12:03.509450 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T13:12:03.377831+00:00 app[web.1]: * Environment: production
2018-10-11T13:12:03.395400+00:00 app[web.1]: I, [2018-10-11T13:12:03.395269 #4]  INFO -- : [236d4168-88a6-4bcc-95fb-612cedba6999] Processing by WelcomeController#index as HTML
2018-10-11T13:12:03.508276+00:00 app[web.1]: I, [2018-10-11T13:12:03.508113 #4]  INFO -- : [236d4168-88a6-4bcc-95fb-612cedba6999] Completed 500 Internal Server Error in 112ms
2018-10-11T13:12:03.377845+00:00 app[web.1]: I, [2018-10-11T13:12:03.377672 #4]  INFO -- : [236d4168-88a6-4bcc-95fb-612cedba6999] Started GET "/" for 107.208.176.45 at 2018-10-11 13:12:03 +0000
2018-10-11T13:12:03.509854+00:00 app[web.1]: F, [2018-10-11T13:12:03.509752 #4] FATAL -- : [236d4168-88a6-4bcc-95fb-612cedba6999] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T13:12:03.941190+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=6e8c624c-0141-4da4-9dbc-426ca3099276 fwd="107.208.176.45" dyno=web.1 connect=1ms service=4ms status=200 bytes=143 protocol=https
2018-10-11T13:15:25.880221+00:00 heroku[web.1]: Restarting
2018-10-11T13:15:25.880730+00:00 heroku[web.1]: State changed from up to starting
2018-10-11T13:15:26.736019+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-10-11T13:15:26.814218+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2018-10-11T13:15:26.834175+00:00 app[web.1]: === puma shutdown: 2018-10-11 13:15:26 +0000 ===
2018-10-11T13:15:26.834492+00:00 app[web.1]: Exiting
2018-10-11T13:15:26.834261+00:00 app[web.1]: - Goodbye!
2018-10-11T13:15:27.169490+00:00 heroku[web.1]: Process exited with status 143
2018-10-11T13:15:29.605096+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 29987 -e production`
2018-10-11T13:15:35.374170+00:00 heroku[web.1]: State changed from starting to up
2018-10-11T13:16:47.479481+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=ca9b9cf4-45bb-4139-8397-748a53ff1ecd fwd="107.208.176.45" dyno=web.1 connect=0ms service=60ms status=500 bytes=1827 protocol=https
2018-10-11T13:16:47.423357+00:00 app[web.1]: => Booting Puma
2018-10-11T13:16:47.423392+00:00 app[web.1]: => Rails 5.2.1 application starting in production
2018-10-11T13:16:47.423394+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-10-11T13:16:47.423399+00:00 app[web.1]: Puma starting in single mode...
2018-10-11T13:16:47.423401+00:00 app[web.1]: * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
2018-10-11T13:16:47.423407+00:00 app[web.1]: * Min threads: 5, max threads: 5
2018-10-11T13:16:47.423408+00:00 app[web.1]: * Environment: production
2018-10-11T13:16:47.423411+00:00 app[web.1]: Use Ctrl-C to stop
2018-10-11T13:16:47.423410+00:00 app[web.1]: * Listening on tcp://0.0.0.0:29987
2018-10-11T13:16:47.423419+00:00 app[web.1]: I, [2018-10-11T13:16:47.423133 #4]  INFO -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] Started GET "/" for 107.208.176.45 at 2018-10-11 13:16:47 +0000
2018-10-11T13:16:47.433037+00:00 app[web.1]: I, [2018-10-11T13:16:47.432896 #4]  INFO -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] Processing by WelcomeController#index as HTML
2018-10-11T13:16:47.477319+00:00 app[web.1]: I, [2018-10-11T13:16:47.477177 #4]  INFO -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] Completed 500 Internal Server Error in 39ms
2018-10-11T13:16:47.478108+00:00 app[web.1]: F, [2018-10-11T13:16:47.478014 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd]
2018-10-11T13:16:47.478185+00:00 app[web.1]: F, [2018-10-11T13:16:47.478103 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T13:16:47.478322+00:00 app[web.1]: F, [2018-10-11T13:16:47.478183 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd]
2018-10-11T13:16:47.478406+00:00 app[web.1]: F, [2018-10-11T13:16:47.478327 #4] FATAL -- : [ca9b9cf4-45bb-4139-8397-748a53ff1ecd] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T13:16:47.911583+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=d45521a1-be85-47f5-a36c-ffffcddbfe5a fwd="107.208.176.45" dyno=web.1 connect=0ms service=1ms status=304 bytes=48 protocol=https
2018-10-11T13:31:53.937375+00:00 app[web.1]: I, [2018-10-11T13:31:53.937211 #4]  INFO -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] Started GET "/" for 107.208.176.45 at 2018-10-11 13:31:53 +0000
2018-10-11T13:31:53.938482+00:00 app[web.1]: I, [2018-10-11T13:31:53.938396 #4]  INFO -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] Processing by WelcomeController#index as HTML
2018-10-11T13:31:53.965078+00:00 app[web.1]: I, [2018-10-11T13:31:53.964899 #4]  INFO -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] Completed 500 Internal Server Error in 26ms
2018-10-11T13:31:53.966246+00:00 app[web.1]: F, [2018-10-11T13:31:53.966126 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b]
2018-10-11T13:31:53.966365+00:00 app[web.1]: F, [2018-10-11T13:31:53.966277 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T13:31:53.966447+00:00 app[web.1]: F, [2018-10-11T13:31:53.966367 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b]
2018-10-11T13:31:53.966553+00:00 app[web.1]: F, [2018-10-11T13:31:53.966462 #4] FATAL -- : [bb6be014-e6b9-46da-88d4-1b3bec87236b] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T13:31:54.111275+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=ca2791a5-20a1-4232-9d7d-e22b54f5cef0 fwd="107.208.176.45" dyno=web.1 connect=1ms service=2ms status=200 bytes=143 protocol=https
2018-10-11T13:31:53.967004+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=bb6be014-e6b9-46da-88d4-1b3bec87236b fwd="107.208.176.45" dyno=web.1 connect=1ms service=33ms status=500 bytes=1827 protocol=https
2018-10-11T14:08:06.626516+00:00 heroku[web.1]: Idling
2018-10-11T14:08:06.627170+00:00 heroku[web.1]: State changed from up to down
2018-10-11T14:08:07.504722+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-10-11T14:08:07.522614+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2018-10-11T14:08:07.540228+00:00 app[web.1]: === puma shutdown: 2018-10-11 14:08:07 +0000 ===
2018-10-11T14:08:07.540234+00:00 app[web.1]: - Goodbye!
2018-10-11T14:08:07.541182+00:00 app[web.1]: Exiting
2018-10-11T14:08:07.697959+00:00 heroku[web.1]: Process exited with status 143
2018-10-11T14:47:20.384445+00:00 heroku[web.1]: State changed from down to starting
2018-10-11T14:47:25.692081+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 27996 -e production`
2018-10-11T14:47:38.701112+00:00 heroku[web.1]: State changed from starting to up
2018-10-11T14:48:50.067467+00:00 heroku[router]: at=info method=GET path="/" host=tellmetele.herokuapp.com request_id=1dc30c3e-bf46-4fdd-9e60-6ada594823af fwd="107.208.176.45" dyno=web.1 connect=0ms service=55ms status=500 bytes=1827 protocol=https
2018-10-11T14:48:50.014148+00:00 app[web.1]: => Rails 5.2.1 application starting in production
2018-10-11T14:48:50.014150+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-10-11T14:48:50.014152+00:00 app[web.1]: Puma starting in single mode...
2018-10-11T14:48:50.014153+00:00 app[web.1]: * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
2018-10-11T14:48:50.014155+00:00 app[web.1]: * Min threads: 5, max threads: 5
2018-10-11T14:48:50.014157+00:00 app[web.1]: * Environment: production
2018-10-11T14:48:50.014122+00:00 app[web.1]: => Booting Puma
2018-10-11T14:48:50.014158+00:00 app[web.1]: * Listening on tcp://0.0.0.0:27996
2018-10-11T14:48:50.014160+00:00 app[web.1]: Use Ctrl-C to stop
2018-10-11T14:48:50.014172+00:00 app[web.1]: I, [2018-10-11T14:48:50.013977 #4]  INFO -- : [1dc30c3e-bf46-4fdd-9e60-6ada594823af] Started GET "/" for 107.208.176.45 at 2018-10-11 14:48:50 +0000
2018-10-11T14:48:50.019052+00:00 app[web.1]: I, [2018-10-11T14:48:50.018956 #4]  INFO -- : [1dc30c3e-bf46-4fdd-9e60-6ada594823af] Processing by WelcomeController#index as HTML
2018-10-11T14:48:50.061273+00:00 app[web.1]: I, [2018-10-11T14:48:50.061050 #4]  INFO -- : [1dc30c3e-bf46-4fdd-9e60-6ada594823af] Completed 500 Internal Server Error in 41ms
2018-10-11T14:48:50.064466+00:00 app[web.1]: F, [2018-10-11T14:48:50.064359 #4] FATAL -- : [1dc30c3e-bf46-4fdd-9e60-6ada594823af]
2018-10-11T14:48:50.064594+00:00 app[web.1]: F, [2018-10-11T14:48:50.064521 #4] FATAL -- : [1dc30c3e-bf46-4fdd-9e60-6ada594823af] NoMethodError (undefined method `take' for nil:NilClass):
2018-10-11T14:48:50.064702+00:00 app[web.1]: F, [2018-10-11T14:48:50.064621 #4] FATAL -- : [1dc30c3e-bf46-4fdd-9e60-6ada594823af]
2018-10-11T14:48:50.064805+00:00 app[web.1]: F, [2018-10-11T14:48:50.064740 #4] FATAL -- : [1dc30c3e-bf46-4fdd-9e60-6ada594823af] app/controllers/welcome_controller.rb:4:in `index'
2018-10-11T14:48:50.593266+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tellmetele.herokuapp.com request_id=05f75b86-c9f9-4328-a4a2-883ae82898f4 fwd="107.208.176.45" dyno=web.1 connect=1ms service=6ms status=200 bytes=143 protocol=https

它似乎是。欢迎控制器的问题。这是控制器

class WelcomeController < ApplicationController

  def index
    parsed_response = Tv.get_popular_shows
    popular_shows = parsed_response['results'].take(8)
    pages = parsed_response['total_pages']

    render :index, locals: {
      parsed_response: parsed_response,
      popular_shows: popular_shows,
      pages: pages
    }
  end
end

这是欢迎索引视图文件

<h1 class="w3-center">TVs' Most Popular</h1>
<section class="w3-content">
  <% popular_shows.each do |show| %>
    <%= link_to image_tag("https://image.tmdb.org/t/p/w200/#{show['poster_path']}", :alt => "#{show['original_name']} image.", class: "poster w3-image w3-padding w3-card"), root_url + 'tvs/show?' + {tvid: show['id']}.to_param, method: :get %>
  <% end %>
</section>

以下是 get_popular_shows 的定义方式:

class Tv < ApplicationRecord
  include HTTParty

  base_uri 'https://api.themoviedb.org/3'
  default_params api_key: ENV['API_KEY']
  format :json

  def Tv.get_all_shows(page, sort)
    get("/discover/tv", query: {sort_by: sort, page: page})
  end

  def Tv.get_popular_shows
    get("/discover/tv", query: {sort_by: "popularity.desc"})
  end

  def Tv.get_single_show(tv_id)
    get("/tv/#{tv_id}",query: {})
  end

end

这根本不符合逻辑。该应用程序在本地运行并在 Heroku 上启动。我阅读并尝试了很多解决方案均无济于事。我不知道从这里去哪里。任何帮助都感激不尽。提前致谢。

标签: ruby-on-railsherokuruby-on-rails-5

解决方案


推荐阅读