<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: url code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 23:39:13 GMT</pubDate>
    <description>DZone Snippets: url code</description>
    <item>
      <title>Validate URIs by Pinging the Server</title>
      <link>http://snippets.dzone.com/posts/show/1913</link>
      <description>&lt;code&gt;&lt;br /&gt;require 'open-uri'&lt;br /&gt;&lt;br /&gt;class ActiveRecord::Base&lt;br /&gt;  def self.validates_uri_existence_of(*attr_names)&lt;br /&gt;    configuration = { :message =&gt; "is not a valid web address" }&lt;br /&gt;    configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)&lt;br /&gt;    validates_each attr_names do |m, a, v|&lt;br /&gt;      begin&lt;br /&gt;        # Try to open the URI&lt;br /&gt;        open v&lt;br /&gt;      rescue&lt;br /&gt;        # Report the error if it throws an exception&lt;br /&gt;        m.errors.add(a, configuration[:message])&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Details on my blog.</description>
      <pubDate>Fri, 14 Apr 2006 02:12:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1913</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
  </channel>
</rss>
