应用程序在本地工作但不在Heroku上工作

时间:2013-12-12 13:59:03

标签: ruby-on-rails ruby heroku

我的“show.html.erb”中有这段代码

<div><blockquote class="pull-left">
          <p id="mycontainer"><%= @l.content %> </p>
          <small><%= @l.author %> </small>
          <button class="btn btn-mini", "pull=right" type="button">Następny -></button>
        </blockquote></div>
      </div>

在我的“kalendar_controller.rb”中我有:

  def show

   @l = Joke.find_by(id: rand(1..Joke.count)) 
   @t = Time.now.strftime("%A")
   @week = Date.today.cweek % 2 == 0 ? "#{trans} " "PARZYSTE" : "NIEPARZYSTE"
  end

我在heroku上运行了这些代码:

$ git push
$ git push heroku
$ heroku run rake db:migrate

一切都在本地工作所以我希望它能在Heroku上运行。但后来我受到了欢迎

  

我们很抱歉,但出了点问题。

此时我不确定发生了什么。我检查了heroku日志,发现这个ActionView::Template::Error (undefined method内容为nil:NilClass):maybe this could be the problem (not sure yet though). But I have @ l defined which picks a random joke from the database so why is the log mentioning nil:NilClass`。有任何帮助解决这个问题吗?

编辑:

我的heroku日志:

2013-12-12T13:38:13.734760+00:00 app[web.1]:   Rendered kalendar/show.html.erb within layouts/application (0.8ms)
2013-12-12T13:38:13.735007+00:00 app[web.1]: Completed 500 Internal Server Error in 11ms
2013-12-12T13:38:13.737468+00:00 app[web.1]: ActionView::Template::Error (undefined method `content' for nil:NilClass):
2013-12-12T13:38:13.735007+00:00 app[web.1]: Completed 500 Internal Server Error in 11ms
2013-12-12T13:38:13.737468+00:00 app[web.1]: 
2013-12-12T13:38:13.737468+00:00 app[web.1]:      7:        <center><h6>Dzisiaj jest: <span class="label label-info"><%= Time.now.strftime("%d.%m.%Y") %></span><iframe class="pull-right" src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FPWr-Kalendarz%2F622999367760849&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=false&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe></h6></center>
2013-12-12T13:38:13.737468+00:00 app[web.1]:      8:   
2013-12-12T13:38:13.737468+00:00 app[web.1]:      9:        <div><blockquote class="pull-left">
2013-12-12T13:38:13.737468+00:00 app[web.1]:     11:          <small><%= @l.author %> </small>
2013-12-12T13:38:13.737468+00:00 app[web.1]:     10:          <p id="mycontainer"><%= @l.content %> </p>
2013-12-12T13:38:13.737468+00:00 app[web.1]:     12:          <button class="btn btn-mini", "pull=right" type="button">Następny -></button>
2013-12-12T13:38:13.737468+00:00 app[web.1]:     13:        </blockquote></div>
2013-12-12T13:38:13.737825+00:00 app[web.1]: 
2013-12-12T13:38:13.737468+00:00 app[web.1]:   app/views/kalendar/show.html.erb:10:in `_app_views_kalendar_show_html_erb___3142504778803122676_70084739238140'
2013-12-12T13:38:13.737825+00:00 app[web.1]: 
2013-12-12T13:38:13.739896+00:00 app[web.1]: 
2013-12-12T13:38:13.739896+00:00 app[web.1]: ActionView::Template::Error (undefined method `content' for nil:NilClass):
2013-12-12T13:38:13.739896+00:00 app[web.1]:      7:        <center><h6>Dzisiaj jest: <span class="label label-info"><%= Time.now.strftime("%d.%m.%Y") %></span><iframe class="pull-right" src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FPWr-Kalendarz%2F622999367760849&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=false&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe></h6></center>
2013-12-12T13:38:13.739896+00:00 app[web.1]:      8:   
2013-12-12T13:38:13.739896+00:00 app[web.1]:     10:          <p id="mycontainer"><%= @l.content %> </p>
2013-12-12T13:38:13.739896+00:00 app[web.1]:      9:        <div><blockquote class="pull-left">
2013-12-12T13:38:13.739896+00:00 app[web.1]:     11:          <small><%= @l.author %> </small>
2013-12-12T13:38:13.739896+00:00 app[web.1]:     12:          <button class="btn btn-mini", "pull=right" type="button">Następny -></button>
2013-12-12T13:38:13.739896+00:00 app[web.1]:     13:        </blockquote></div>
2013-12-12T13:38:13.739896+00:00 app[web.1]:   app/views/kalendar/show.html.erb:10:in `_app_views_kalendar_show_html_erb___3142504778803122676_70084739238140'
2013-12-12T13:38:13.740233+00:00 app[web.1]: 
2013-12-12T13:38:13.740233+00:00 app[web.1]: 
2013-12-12T13:38:13.741057+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=0ms service=25ms status=500 bytes=1266
2013-12-12T13:42:13.686261+00:00 app[web.1]: Processing by KalendarController#show as HTML
2013-12-12T13:42:13.685334+00:00 app[web.1]: Started GET "/" for 90.156.104.195 at 2013-12-12 13:42:13 +0000
2013-12-12T13:42:13.685334+00:00 app[web.1]: Started GET "/" for 90.156.104.195 at 2013-12-12 13:42:13 +0000
2013-12-12T13:42:13.686261+00:00 app[web.1]: Processing by KalendarController#show as HTML
2013-12-12T13:42:13.700988+00:00 app[web.1]: Completed 500 Internal Server Error in 15ms
2013-12-12T13:42:13.700988+00:00 app[web.1]:   Rendered kalendar/show.html.erb within layouts/application (0.8ms)
2013-12-12T13:42:13.700988+00:00 app[web.1]:   Rendered kalendar/show.html.erb within layouts/application (0.8ms)
2013-12-12T13:42:13.702991+00:00 app[web.1]:      8:   
2013-12-12T13:42:13.702991+00:00 app[web.1]:     11:          <small><%= @l.author %> </small>
2013-12-12T13:42:13.702991+00:00 app[web.1]:      9:        <div><blockquote class="pull-left">
2013-12-12T13:42:13.703331+00:00 app[web.1]: 
2013-12-12T13:42:13.702991+00:00 app[web.1]:     10:          <p id="mycontainer"><%= @l.content %> </p>
2013-12-12T13:42:13.702991+00:00 app[web.1]:     12:          <button class="btn btn-mini", "pull=right" type="button">Następny -></button>
2013-12-12T13:42:13.702991+00:00 app[web.1]:     13:        </blockquote></div>
2013-12-12T13:42:13.703331+00:00 app[web.1]:      8:   
2013-12-12T13:42:13.703331+00:00 app[web.1]:     11:          <small><%= @l.author %> </small>
2013-12-12T13:42:13.703331+00:00 app[web.1]:     10:          <p id="mycontainer"><%= @l.content %> </p>
2013-12-12T13:42:13.703331+00:00 app[web.1]:      7:        <center><h6>Dzisiaj jest: <span class="label label-info"><%= Time.now.strftime("%d.%m.%Y") %></span><iframe class="pull-right" src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FPWr-Kalendarz%2F622999367760849&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=false&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe></h6></center>
2013-12-12T13:42:13.702991+00:00 app[web.1]:   app/views/kalendar/show.html.erb:10:in `_app_views_kalendar_show_html_erb___3142504778803122676_70084739238140'
2013-12-12T13:42:13.703331+00:00 app[web.1]: 
2013-12-12T13:42:13.703331+00:00 app[web.1]: 
2013-12-12T13:42:13.703331+00:00 app[web.1]:      9:        <div><blockquote class="pull-left">
2013-12-12T13:42:13.703608+00:00 app[web.1]: 
2013-12-12T13:42:13.703331+00:00 app[web.1]:     12:          <button class="btn btn-mini", "pull=right" type="button">Następny -></button>
2013-12-12T13:42:13.703331+00:00 app[web.1]: ActionView::Template::Error (undefined method `content' for nil:NilClass):
2013-12-12T13:42:13.703608+00:00 app[web.1]:   app/views/kalendar/show.html.erb:10:in `_app_views_kalendar_show_html_erb___3142504778803122676_70084739238140'
2013-12-12T13:42:13.703608+00:00 app[web.1]:     13:        </blockquote></div>
2013-12-12T13:42:13.703608+00:00 app[web.1]: 
2013-12-12T13:42:13.700988+00:00 app[web.1]: Completed 500 Internal Server Error in 15ms
2013-12-12T13:42:13.702991+00:00 app[web.1]:      7:        <center><h6>Dzisiaj jest: <span class="label label-info"><%= Time.now.strftime("%d.%m.%Y") %></span><iframe class="pull-right" src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FPWr-Kalendarz%2F622999367760849&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=false&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe></h6></center>
2013-12-12T13:42:13.702991+00:00 app[web.1]: 
2013-12-12T13:42:13.702991+00:00 app[web.1]: ActionView::Template::Error (undefined method `content' for nil:NilClass):
2013-12-12T13:42:13.709613+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=2ms service=31ms status=500 bytes=1266
2013-12-12T13:44:05.673627+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T13:44:13.629310+00:00 heroku[run.7282]: State changed from up to complete
2013-12-12T13:44:36.274158+00:00 heroku[run.2266]: State changed from up to complete
2013-12-12T13:44:46.099637+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `select'
2013-12-12T13:44:46.943517+00:00 app[web.1]: [2013-12-12 13:44:46] FATAL SignalException: SIGTERM
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:160:in `start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:32:in `start'
2013-12-12T13:44:46.943708+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
2013-12-12T13:44:46.943708+00:00 app[web.1]: [2013-12-12 13:44:46] INFO  WEBrick::HTTPServer#start done.
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:14:in `run'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `block in start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands/server.rb:84:in `start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
2013-12-12T13:44:46.943708+00:00 app[web.1]: [2013-12-12 13:44:46] INFO  going to shutdown ...
2013-12-12T13:44:46.943708+00:00 app[web.1]:    bin/rails:4:in `require'
2013-12-12T13:44:46.943708+00:00 app[web.1]: Exiting
2013-12-12T13:44:46.943708+00:00 app[web.1]:    bin/rails:4:in `<main>'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
2013-12-12T13:44:48.421969+00:00 heroku[web.1]: Process exited with status 143
2013-12-12T13:44:53.194153+00:00 heroku[web.1]: State changed from starting to up
2013-12-12T13:44:54.886028+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=2ms service=748ms status=500 bytes=1266
2013-12-12T13:44:58.494336+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=52ms status=500 bytes=1266
2013-12-12T13:44:59.893294+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=7ms service=44ms status=500 bytes=1266
2013-12-12T13:45:01.715005+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=113ms status=500 bytes=1266
2013-12-12T13:44:23.059938+00:00 heroku[api]: Starting process with command `bundle exec rake db:populate` by siawmensah@gmail.com
2013-12-12T13:45:22.966815+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=6ms service=33ms status=500 bytes=1266
2013-12-12T13:44:27.944462+00:00 heroku[run.2266]: State changed from starting to up
2013-12-12T13:44:42.439607+00:00 heroku[web.1]: State changed from up to starting
2013-12-12T13:49:22.429144+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T13:49:25.743801+00:00 heroku[run.4519]: Awaiting client
2013-12-12T13:49:25.786121+00:00 heroku[run.4519]: Starting process with command `bundle exec rake db:migrate`
2013-12-12T13:49:25.875234+00:00 heroku[run.4519]: State changed from starting to up
2013-12-12T13:49:29.211204+00:00 heroku[run.4519]: Process exited with status 0
2013-12-12T13:49:29.238443+00:00 heroku[run.4519]: State changed from up to complete
2013-12-12T13:49:34.966709+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=34ms status=500 bytes=1266
2013-12-12T13:51:03.227983+00:00 heroku[run.9695]: State changed from up to complete
2013-12-12T13:51:08.517393+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=27ms status=500 bytes=1266
2013-12-12T13:51:09.560231+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=3ms service=25ms status=500 bytes=1266

我也确实运行了heroku run rake db:populate,这甚至都行不通。

最新日志:

Last login: Thu Dec 12 19:18:11 on ttys003
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /Users/siaW/Desktop/kalendar/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.

emmanuels-imac:kalendar siaW$ heroku logs
2013-12-12T13:42:13.703608+00:00 app[web.1]:     13:        </blockquote></div>
2013-12-12T13:42:13.703608+00:00 app[web.1]: 
2013-12-12T13:42:13.700988+00:00 app[web.1]: Completed 500 Internal Server Error in 15ms
2013-12-12T13:42:13.702991+00:00 app[web.1]:      7:        <center><h6>Dzisiaj jest: <span class="label label-info"><%= Time.now.strftime("%d.%m.%Y") %></span><iframe class="pull-right" src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FPWr-Kalendarz%2F622999367760849&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=false&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe></h6></center>
2013-12-12T13:42:13.702991+00:00 app[web.1]: 
2013-12-12T13:42:13.702991+00:00 app[web.1]: ActionView::Template::Error (undefined method `content' for nil:NilClass):
2013-12-12T13:42:13.709613+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=2ms service=31ms status=500 bytes=1266
2013-12-12T13:44:05.673627+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T13:44:13.629310+00:00 heroku[run.7282]: State changed from up to complete
2013-12-12T13:44:36.274158+00:00 heroku[run.2266]: State changed from up to complete
2013-12-12T13:44:46.099637+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `select'
2013-12-12T13:44:46.943517+00:00 app[web.1]: [2013-12-12 13:44:46] FATAL SignalException: SIGTERM
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:160:in `start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:32:in `start'
2013-12-12T13:44:46.943708+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
2013-12-12T13:44:46.943708+00:00 app[web.1]: [2013-12-12 13:44:46] INFO  WEBrick::HTTPServer#start done.
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:14:in `run'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `block in start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands/server.rb:84:in `start'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
2013-12-12T13:44:46.943708+00:00 app[web.1]: [2013-12-12 13:44:46] INFO  going to shutdown ...
2013-12-12T13:44:46.943708+00:00 app[web.1]:    bin/rails:4:in `require'
2013-12-12T13:44:46.943708+00:00 app[web.1]: Exiting
2013-12-12T13:44:46.943708+00:00 app[web.1]:    bin/rails:4:in `<main>'
2013-12-12T13:44:46.943517+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
2013-12-12T13:44:48.421969+00:00 heroku[web.1]: Process exited with status 143
2013-12-12T13:44:53.194153+00:00 heroku[web.1]: State changed from starting to up
2013-12-12T13:44:54.886028+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=2ms service=748ms status=500 bytes=1266
2013-12-12T13:44:58.494336+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=52ms status=500 bytes=1266
2013-12-12T13:44:59.893294+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=7ms service=44ms status=500 bytes=1266
2013-12-12T13:45:01.715005+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=113ms status=500 bytes=1266
2013-12-12T13:44:23.059938+00:00 heroku[api]: Starting process with command `bundle exec rake db:populate` by siawmensah@gmail.com
2013-12-12T13:45:22.966815+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=6ms service=33ms status=500 bytes=1266
2013-12-12T13:44:27.944462+00:00 heroku[run.2266]: State changed from starting to up
2013-12-12T13:44:42.439607+00:00 heroku[web.1]: State changed from up to starting
2013-12-12T13:49:22.429144+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T13:49:25.743801+00:00 heroku[run.4519]: Awaiting client
2013-12-12T13:49:25.786121+00:00 heroku[run.4519]: Starting process with command `bundle exec rake db:migrate`
2013-12-12T13:49:25.875234+00:00 heroku[run.4519]: State changed from starting to up
2013-12-12T13:49:29.211204+00:00 heroku[run.4519]: Process exited with status 0
2013-12-12T13:49:29.238443+00:00 heroku[run.4519]: State changed from up to complete
2013-12-12T13:49:34.966709+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=34ms status=500 bytes=1266
2013-12-12T13:51:03.227983+00:00 heroku[run.9695]: State changed from up to complete
2013-12-12T13:51:08.517393+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=27ms status=500 bytes=1266
2013-12-12T13:51:09.560231+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=3ms service=25ms status=500 bytes=1266
2013-12-12T13:52:05.530539+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=3ms service=33ms status=500 bytes=1266
2013-12-12T14:01:12.840421+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=8ms service=32ms status=500 bytes=1266
2013-12-12T14:01:13.798926+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=5ms service=30ms status=500 bytes=1266
2013-12-12T14:02:25.893053+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=9ms service=28ms status=500 bytes=1266
2013-12-12T14:10:40.052935+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=7ms service=100ms status=500 bytes=1266
2013-12-12T14:17:42.867494+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=28ms status=500 bytes=1266
2013-12-12T14:19:04.381488+00:00 heroku[api]: Starting process with command `bundle exec rake db:populate` by siawmensah@gmail.com
2013-12-12T14:19:09.039027+00:00 heroku[run.2181]: State changed from starting to up
2013-12-12T14:19:09.145701+00:00 heroku[run.2181]: Awaiting client
2013-12-12T14:19:09.288308+00:00 heroku[run.2181]: Starting process with command `bundle exec rake db:populate`
2013-12-12T14:19:12.831097+00:00 heroku[run.2181]: Process exited with status 1
2013-12-12T14:19:12.860881+00:00 heroku[run.2181]: State changed from up to complete
2013-12-12T14:23:08.011600+00:00 heroku[api]: Starting process with command `bundle exec rake db:populate` by siawmensah@gmail.com
2013-12-12T14:23:13.078679+00:00 heroku[run.4911]: State changed from starting to up
2013-12-12T14:23:13.533233+00:00 heroku[run.4911]: Awaiting client
2013-12-12T14:23:13.581313+00:00 heroku[run.4911]: Starting process with command `bundle exec rake db:populate`
2013-12-12T14:23:19.847369+00:00 heroku[run.4911]: Process exited with status 1
2013-12-12T14:23:19.860400+00:00 heroku[run.4911]: State changed from up to complete
2013-12-12T14:26:31.825431+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T14:26:36.581342+00:00 heroku[run.4120]: Awaiting client
2013-12-12T14:26:36.626793+00:00 heroku[run.4120]: Starting process with command `bundle exec rake db:migrate`
2013-12-12T14:26:41.855736+00:00 heroku[run.4120]: State changed from up to complete
2013-12-12T14:26:41.839844+00:00 heroku[run.4120]: Process exited with status 0
2013-12-12T14:26:50.477466+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=37ms status=500 bytes=1266
2013-12-12T14:29:14.123333+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T14:29:18.312942+00:00 heroku[run.3578]: Awaiting client
2013-12-12T14:29:18.371912+00:00 heroku[run.3578]: Starting process with command `bundle exec rake db:migrate`
2013-12-12T14:29:18.471482+00:00 heroku[run.3578]: State changed from starting to up
2013-12-12T14:29:23.362281+00:00 heroku[run.3578]: Process exited with status 0
2013-12-12T14:31:05.504490+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=16ms service=46ms status=500 bytes=1266
2013-12-12T14:29:23.379276+00:00 heroku[run.3578]: State changed from up to complete
2013-12-12T14:35:18.938824+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T14:35:22.937717+00:00 heroku[run.9410]: State changed from starting to up
2013-12-12T14:35:26.995322+00:00 heroku[run.9410]: State changed from up to complete
2013-12-12T14:35:30.893618+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=3ms service=34ms status=500 bytes=1266
2013-12-12T14:35:22.744507+00:00 heroku[run.9410]: Awaiting client
2013-12-12T14:35:22.803390+00:00 heroku[run.9410]: Starting process with command `bundle exec rake db:migrate`
2013-12-12T14:35:26.979877+00:00 heroku[run.9410]: Process exited with status 0
2013-12-12T14:38:53.954686+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=5ms service=258ms status=500 bytes=1266
2013-12-12T14:41:40.175479+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=2ms service=89ms status=500 bytes=1266
2013-12-12T14:49:29.480931+00:00 heroku[run.2515]: State changed from starting to up
2013-12-12T14:50:54.030490+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by siawmensah@gmail.com
2013-12-12T14:50:58.893089+00:00 heroku[run.7658]: State changed from starting to up
2013-12-12T14:50:58.975265+00:00 heroku[run.7658]: Awaiting client
2013-12-12T14:50:59.005656+00:00 heroku[run.7658]: Error R13 (Attach error) -> Failed to attach to process
2013-12-12T14:51:00.699641+00:00 heroku[run.7658]: Process exited with status 128
2013-12-12T14:51:01.199142+00:00 heroku[run.7658]: State changed from up to complete
2013-12-12T14:50:00.792442+00:00 heroku[run.2515]: State changed from up to complete
2013-12-12T14:52:27.379216+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=2ms service=255ms status=500 bytes=1266
2013-12-12T14:53:12.077208+00:00 heroku[run.3491]: State changed from up to complete
2013-12-12T14:54:17.017016+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=1ms service=33ms status=500 bytes=1266
2013-12-12T14:54:44.964666+00:00 heroku[router]: at=info method=GET path=/ host=hidden-river-2301.herokuapp.com fwd="90.156.104.195" dyno=web.1 connect=6ms service=32ms status=500 bytes=1266
2013-12-12T15:57:38.455980+00:00 heroku[web.1]: Idling
2013-12-12T15:57:38.456870+00:00 heroku[web.1]: State changed from up to down
emmanuels-imac:kalendar siaW$ 

3 个答案:

答案 0 :(得分:2)

您的随机方法有时返回数据库中不存在的id值,因此find_by方法返回nil而不是引发错误,这很好。

然而,我没有使用Donovan的方法在不存在时显示消息,而是建议您从现有ID的现有数组中随机选择一个ID值。

示例:

random_id = Joke.all.map(&:id).sample
@joke = Joke.find_by_id(random_id)

现在你需要做的是确保填充数据库,因为[] .sample仍然返回nil。

编辑: 另外我建议在处理变量名时使用逻辑,当返回单个Joke对象时使用@joke,当使用@jokes返回一个笑话数组时,这将使它更容易理解。

答案 1 :(得分:0)

添加一个简单的检查以确保@l在尝试显示之前有效,如下所示:

<p id="mycontainer"><%= @l.nil? ? 'No jokes found, sorry' : @l.content %> </p>

答案 2 :(得分:0)

rand()无法在heroku上运行

尝试:

@l = Joke.all.sample