Validates Url plugin

Plugin details

Allows models with HTTP URL fields to validate those URL fields by attempting to connect to the URL. Validation will fail unless a connection is successfully made and the URL is an HTTP URL.

Repositoryhttp://validates-url.googlecode.com/svn/trunk/ Author Tim Morgan Tags url, validation LicenseRuby's (MIT)

Documentation

Install the plugin:
ruby script/plugin install http://validates-url.googlecode.com/svn/trunk/

Validates that a URL is accessible and is an HTTP URL by opening a connection to the server.

class Company < ActiveRecord::Base
	validates_http_url :homepage, :wrong_response => "did not return a successful HTTP code"
end



Configuration options:

* valid_responses - An array of valid HTTP responses (as subclasses of Net::HTTPResponse). By default this contains Net::HTTPSuccess (and therefore all subclasses of it, such as Net::HTTPOK). If you would like to add your own valid responses, make sure to include Net::HTTPSuccess unless you explicitly want to remove it from the set of valid responses.

* wrong_response - A custom error message for when the server does not return a valid HTTP response
* wrong_protocol - A custom error message for when the URL provided is not an HTTP URL
* malformed_url - A custom error message for when a malformed URL is provided
* no_response - A custom error message for when there is no response, the connection is refused, or unexpectedly reset
* timeout - A custom error message for when the connection times out
* message - A custom error message to be used for any of the above error messages that are not specified

If you would like to specify a custom error message for a particular response code, pass a hash instead of a string for wrong_response. Map each Net::HTTPResponse subclass to the error message you'd like to use for that response. If you map an error message to Net::HTTPResponse, it will be used as the default error message for response codes without custom error messages. An example:

validates_http_url :url, :wrong_response => { Net::HTTPMovedPermanently => "has been moved", Net::HTTPResponse => "is not working correctly" }


Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: Guest, 9 months ago