Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Improved support for shortcut options to custom validators

#5672

Because of the current implementation of _parse_validates_options, you can only "shortcut" options with arrays, ranges and regexes. This patch expands that feature to so that you can also send other types of objects including strings and numbers. They will be passed to the custom validator's initializer as options[:with], just like happens with regexes now.

# current functionality
validates :email, :format => /@/
validates :gender, :inclusion => %w(male female)
validates :password, :length => 6..20

# new functionality in this patch
validates :name, :like => "Report"
validates :number, :base => 10

Reported by Obie · September 21st, 2010 @ 02:50 AM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to open
    • Importance changed from to Low

    The patch had trailing whitespace warnings. Attached is a new patch with those removed.

    +1 on the patch.

    September 21st, 2010 @ 03:06 AM

  2. Obie
    Obie

    @Rohit: Thanks for fixing the patch and the +1

    September 21st, 2010 @ 03:09 AM

  3. Repository
    Repository
    • State changed from open to resolved

    (from [275f922a23b780600a32f70de5b661371c8ffdf4]) Better shortcut options for custom validators [#5672 state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/275f922a23b780600a32f70de5b661...

    September 24th, 2010 @ 12:11 PM