Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails-错误500_Ruby On Rails_Ruby_Error Handling - Fatal编程技术网

Ruby on rails RubyonRails-错误500

Ruby on rails RubyonRails-错误500,ruby-on-rails,ruby,error-handling,Ruby On Rails,Ruby,Error Handling,我有一个运行ruby on rails的客户,不幸的是我不是100%喜欢ruby。。。无论如何,今天他们的网站在浏览网站时总是返回错误500 查看错误日志,我只能看到以下内容: [ 2015-11-16 20:16:45.5125 11424/7fcdb8049700 Pool2/SmartSpawner.h:298 ]: Preloader for /home/rails/production started on PID 22379, listening on unix:/tmp/p$ Ap

我有一个运行ruby on rails的客户,不幸的是我不是100%喜欢ruby。。。无论如何,今天他们的网站在浏览网站时总是返回错误500

查看错误日志,我只能看到以下内容:

[ 2015-11-16 20:16:45.5125 11424/7fcdb8049700 Pool2/SmartSpawner.h:298 ]: Preloader for /home/rails/production started on PID 22379, listening on unix:/tmp/p$
App 22504 stdout:
App 22950 stdout:
App 22950 stderr: /home/rails/.rvm/gems/ruby-1.9.3-p484/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant SMTPSession
App 22950 stderr: /home/rails/.rvm/gems/ruby-1.9.3-p484/gems/tlsmail-0.0.1/lib/net/pop.rb:687: warning: already initialized constant POP
App 22950 stderr: /home/rails/.rvm/gems/ruby-1.9.3-p484/gems/tlsmail-0.0.1/lib/net/pop.rb:688: warning: already initialized constant POPSession
App 22950 stderr: /home/rails/.rvm/gems/ruby-1.9.3-p484/gems/tlsmail-0.0.1/lib/net/pop.rb:689: warning: already initialized constant POP3Session
App 22950 stderr: /home/rails/.rvm/gems/ruby-1.9.3-p484/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: already initialized constant APOPSession
App 22950 stdout: MultiParameterHack loaded
App 22950 stderr: [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set$
[ 2015-11-16 20:33:27.7232 11424/7fcdb9f61700 Pool2/SmartSpawner.h:298 ]: Preloader for /home/rails/production started on PID 22950, listening on unix:/tmp/p$
App 23101 stdout:
有人能帮我解释一下吗

我也可以在production.log中看到这一点:

Rendered shared/_meganav.html.erb (86.0ms)
Rendered pages/home.html.erb within layouts/application (197.9ms)
Completed 500 Internal Server Error in 278ms
** [Airbrake] Success: Net::HTTPOK
** [Airbrake] Environment Info: [Ruby: 1.9.3] [Rails: 3.0.19] [Env: production]
** [Airbrake] Response from Airbrake:
UUID: 1555278126118213905
URL:  https://airbrake.io/locate/1555278126118213905

ActionView::Template::Error (undefined method `has_image?' for nil:NilClass):
    269:                           <% event = Event.featured.newest.first %>
    270:
    271:              <article class="featured-event">
    272:                <% if event.has_image? %>
    273:                <div class="image"><span></span><%= link_to(image_tag(event.image.expiring_url(:featured)), event_path(event)) %></div>
    274:                <% end %>
    275:                  <div class="text">
  app/views/shared/_meganav.html.erb:272:in `_app_views_shared__meganav_html_erb__3450254428998327647_59198060__3999436880091196355'
  app/views/layouts/application.html.erb:223:in `_app_views_layouts_application_html_erb__1905251585106566541_49797400_3662579409495417543'

我怀疑您的问题是没有与featured.newest匹配的事件,这意味着该事件为零。就像尼卢的形象一样?不是一个可用的方法,将抛出一个NoMethodError,最终在服务器上看到一个500错误

事件查询属于您的控制器,您的输出应该有一个nil保护,以确保不会发生这种情况。例如:

# app/controllers/pages_controller.rb
def index
  @event = Event.featured.newest.first
end

# app/views/pages/home.html.erb
<% if @event.present? %>
  <article class="featured-event">
  ...
  </article>
<% end %>
改为:

…或在Ruby中>=2.3

<% if event&.has_image? %>

显然不是日志的相关部分。我们需要更多的数据。嘿@KarlWilbur谢谢你的回复。我应该查看哪些日志?这取决于应用程序和配置。可能是log/production.log。使用什么web服务器?web服务器的错误日志可能也会有帮助。@KarlWilbur上面的错误来自服务器日志/var/log/error\u logI我现在来看看另一个。嗨,coreyward,谢谢这个人,对不起,我从来没有用过ruby。。。是否只需在添加之前添加?根据应用程序的需要,您可能可以在控制器中执行此操作:@event=event.featured.newst.first | | event.new。我已进行了更改,但仍会收到相同的错误?我需要重新编译什么吗?
<% if event&.has_image? %>