【发布时间】:2020-12-30 11:20:24
【问题描述】:
我有一个在 Ruby 2.6.6 上运行的 Ruby on Rails 5.2 应用程序,路径如下:/api/popups 它给了我 500 内部服务器错误。
在生产日志中,我看到以下消息:
Started GET "/api/popups" for IP at 2020-12-30 11:12:30 +0000
INFO -- : [e7a305ff-9d4d-4c83-9572-9ea0708e8f69] Processing by controller2#index as HTML
INFO -- : [e7a305ff-9d4d-4c83-9572-9ea0708e8f69] Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms)
FATAL -- : [e7a305ff-9d4d-4c83-9572-9ea0708e8f69]
FATAL -- : [e7a305ff-9d4d-4c83-9572-9ea0708e8f69] NoMethodError (undefined method `host' for nil:NilClass):
FATAL -- : [e7a305ff-9d4d-4c83-9572-9ea0708e8f69]
FATAL -- : [e7a305ff-9d4d-4c83-9572-9ea0708e8f69] app/controllers/concerns/controller1.rb:14:in `popups_for_domain'
[e7a305ff-9d4d-4c83-9572-9ea0708e8f69] app/controllers/controller2.rb:5:in `index'
controller2.rb 索引(第 5 行)如下所示:
def index
popups = popups_for_domain.includes(:popup_template, :color_schema, :target_sets)
end
controller1.rb 第 14 行包含:
def popups_for_domain
return @popups_for_domain if @popups_for_domain
referer_domain = Addressable::URI.parse(request.referer).host.gsub(/^w{3}\./i, '')
@popups_for_domain = Popup.where(domain: referer_domain)
end
错误从这一行指向主机函数:referer_domain = Addressable::URI.parse(request.referer).host.gsub(/^w{3}\./i, '')
那里出了什么问题,我该如何解决?谢谢。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-5 ruby-on-rails-5.2 ruby-on-rails-5.1