Sha256: 59d2dd81732d665b900c7aa539906650c29bfbb65a2e80c98080f74708baba78

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

== Validates Lengths from Database

Few people add length validations to fields in their database, and when saving such fields that have exhausted their length, an SQL error occurs.
This gem introspects your table schema for maximum lengths on string and text fields and automatically adds length validations to the model.

== Installation

This gem is testing working with Rails 3.0 only!

Include the gem using bundler in your Gemfile:

  gem "validates_lengths_from_database"

== Usage

In your model you can activate validations:

  class Post < ActiveRecord::Base
    validates_lengths_from_database
  end

It also supports filter-style :only and :except options:

  class Post < ActiveRecord::Base
    validates_lengths_from_database :only => [:title, :contents]
  end

  class Post < ActiveRecord::Base
    validates_lengths_from_database :except => [:other_field]
  end

Note that this cannot be done at a global level directly against ActiveRecord::Base, since the +validates_length_from_database+ method requires the class to have a table name (with the ability to load the schema).

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_lengths_from_database-0.0.2 README.rdoc