Home > rails3-custom-validators

rails3-custom-validators

Rails3-custom-validators is a project mainly written in Ruby, it's free.

Custom validations for Rails 3

= Rails 3 Custom Validators

  • Drop the _validator.rb file in /lib
  • Autoload the lib file by updating your application.rb with: config.autoload_paths += %W(#{config.root}/lib)

== DateValidator A very basic date validator that allows you to specify a date that the object's date must be before or after.

Example syntax:

class Batch < ActiveRecord::Base attr_accessor :start_date, :end_date validates :end_date, :date => {:after => {:message => "must be after the start date", :value => lambda { |batch| batch.start_date}}} end

You can also specify:

  • :on_or_after
  • :before
  • :on_or_before

=== Todo Play nicely with Rails i18n.

Previous:vim