0.02
No release in over 3 years
Low commit activity in last 3 years
Validation groups for ActiveRecord
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

> 5.2, < 8
 Project Readme

ValidationGroup¶ ↑

When doing multipage forms that spread a models fields over several pages, validation becomes more difficult. We would like to validate each step of the form, however, the rails validation run validation on all the fields. This plugin enables you to define validation groups with certain fields, and then only run validation on those groups.

Version: Rails 3. To use on Rails 2.x versions, use forked copy from github.com/jeffp/validationgroup

To install:

Add to your Gemfile:

gem 'validation_group'

Example¶ ↑

class User < ActiveRecord::Base
  validates_presence_of :name, :description, :address, :email

  validation_group :step1, :fields=>[:name, :description]
  validation_group :step2, :fields=>[:address]     
end

This will run validation on :step1 fields

@user = User.new
@user.enable_validation_group :step1
@user.valid?

You can later disable validation groups by calling:

@user.disable_validation_group

Copyright © 2007 Alex Kira, released under the MIT license