URLが存在するかどうかを確認しようとしています。これを行うための私のコードは次のとおりです。
validate :registered_domain_name_exists
private
def registered_domain_name_exists
if url and url.match(URI::regexp(%w(http https))) then
begin # check header response
case Net::HTTP.get_response(URI.parse(url))
when Net::HTTPSuccess then true
else errors.add(:url, "URL does not exist") and false
end
rescue # DNS failures
errors.add(:url, "URL does not exist") and false
end
end
end
ただし、このコードは失敗しています。http://www.biorad.comは有効な Web サイトではないと表示されます。これは絶対に間違っています。また、 http : //www.biorad.com があなたを http://www.bio-rad.com/evportal/evolutionPortal.portal にリダイレクトすることを知っている私もこの URL を試しましたが、それも失敗しました。繰り返しますが、これが不可能であることはわかっています。私のコードの何が問題なのですか??