HasValidatedAttributes <img src=“https://secure.travis-ci.org/kylejginavan/has_validated_attributes.png”/>¶ ↑
has_validated_attributes is a Ruby on Rails gem that lets you validate your fields .
add in your Gemfile:
gem 'has_validated_attributes'
in your model:
has_validated_attributes :field => :normalized_type
for example:
class CoolStuff < ActiveRecord::Base has_validated_attributes :username_attr => {:format => :username}, :name_attr => {:format => :name}, :email_attr => {:format => :email}, :phone_number_attr => {:format => :phone_number}, :domain_attr => {:format => :domain}, :phone_extension_attr => {:format => :phone_extension}, :zipcode_attr => {:format => :zipcode}, :middle_initial_attr => {:format => :middle_initial}, :dollar_attr => {:format => :dollar}, :positive_dollar_attr => {:format => :positive_dollar}, :percent_attr => {:format => :percent}, :positive_percent_attr => {:format => :positive_percent}, :url_attr => {:format => :url}, :ssn_attr => {:format => :ssn}, :taxid_attr => {:format => :taxid}, :age_attr => {:format => :age}, :number_attr => {:format => :number} end
You can pass extra options like {:username_attr => {:format => :username, :allow_nil => true, :allow_blank => true, :message => "some message", :if => :food?}
:username, :phone_number, :phone_extension, :person_name, :email, :zipcode, :dollar, :percent, :positive_percent, :middle_initial, :url, :positive_dollar, :domain, :ssn, :taxid, :age, :number
Add ‘require “has_validated_attributes/rspec”` to your specs to include shared examples for validated fields.
Copyright © 2011 Kyle Ginavan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. See LICENSE for details.