0
在我的rails项目中,我试图使用下面的代码,但是我遇到了一个问题,出现以下错误。 undefined local variable or method 'req'
。我不知道我在这里失去了什么。未定义的本地变量`request`
require 'net/http'
...
def url_exist?
url = URI.parse(self.website)
req.use_ssl = (url.scheme == 'https')
req = Net::HTTP.new(url.host, url.port)
path = url.path if url.path.present?
req.request_head(path || '/')
res.code != "404" # false if returns 404 - not found
rescue Errno::ENOENT
false # false if can't find the server
end
这样做后,我'eq.request_head(路径||'/')''方案http不接受注册表部分'的错误,但这可能是另一个问题。 – Scalahansolo
可能。这与订单切换无关。 [这个问题](http://stackoverflow.com/questions/7156885/checking-url-availability-ruby-on-rails)在stackoverflow可能能够帮助你。 –
@SeanCallahan因为这解决了你有'未定义的局部变量或方法'req''这个问题,如果你能将我的答案标记为已接受,那将是非常好的。 –