validate_as_url Gem for Rails 3.x
Validate http and https urls for valid format with standard model validations.
Installation
Installing as a gem:
gem install validate_as_url (recommended)
Or in your Rails 3 Gemfile
gem 'validate_as_url', :git => 'git://github.com/mdima-it-guru/validate_as_url.git'
For use in Rails project add to your Gemfile following line:
gem 'validate_as_url'
Usage
# Rails 3
class Person < ActiveRecord::Base
validate_as_url :website
end
Options
:message_invalid:
String. This messages appears when supplied url has wrong format. Default message: 'does not appear to be valid url',
:message_nil
String. This messages appears when supplied url is nill and 'allow_nil' is false . Default message: 'cannot be null',
:message_blank
String. This messages appears when supplied url is blank string and 'allow_blank' is false . Default message: 'cannot be blank',
:on
Symbol. Specifies when this validation is active (default is :save, other options :create, :update)
:allow_nil
Boolean. Allow nil values (default is false)
:allow_blank
Boolean. Allow blank values (default is false)
Testing
Tested in Ruby 1.9.3
Resources
Credits
Written by Mitrofanov Dmitry (myitguru.info), 2013.