Skip to content

Simple client side validation for Rails that keeps validation in the models

Notifications You must be signed in to change notification settings

overture8/green_light

Repository files navigation

Provides client side validation, with the help of the jquery validation plugin. Keeping validation in the model, where it belongs.

Installation

Add green_light to your Gemfile and run the bundle install command.

gem 'green_light'

Usage

Include the JQuery validation plugin in your app/assets/javascripts/application.js file:-

//= require jquery.validate

Since the validation rules are creating dynmically they need to be included in the header of your layout file:-

<%= javascript_include_tag "green_light" %>

Add the green_light class to the forms that you wish to have client side validation:-

<%= form_for(@model, :html => { :class => 'green_light' }) do |f| %>

And finally, add some validations to your models!

Currently Supports these validations

validates_presence_of
validates_length_of
validates_format_of
validates_uniqueness_of
validates_numericality_of

For validations that are not yet supported, the gem will degrade gracefully to the standard Rails server-side validation.

Legacy Rails 3 Support

For Rails 3 support use the older version (0.0.3) of green_light

Requirements

JQuery is require for the jquery validation plugin. Be sure to include this in your application.js file:-

//= require jquery

Running the Tests

bundle install
bundle exec rspec spec

About

Simple client side validation for Rails that keeps validation in the models

Resources

Stars

Watchers

Forks

Packages

No packages published