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.

validates_non_format_of - the converse of validates_format_of

#430

Considering that there exists validates_inclusion_of/validates_exclusion_of, I figured it would be prudent to have the same relationship established for the format validations.

  class Page < ActiveRecord::Base
    validates_non_format_of :permalink, :with => /^admin/i
  end

Reported by Brennan Dunn · June 16th, 2008 @ 04:21 PM

State: resolved
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Ryan Garver
    Ryan Garver

    I almost want it to be invalidates_format_of

    June 16th, 2008 @ 06:06 PM

  2. Ken Collins
    Ken Collins

    Yes... I like that name better. Too +1

    June 16th, 2008 @ 06:09 PM

  3. Brennan Dunn
    Brennan Dunn

    Agreed. I wasn't feeling creative enough to come up with a decent method name ;-)

    June 16th, 2008 @ 06:31 PM

  4. Alex MacCaw
  5. Pratik
    Pratik
    • Assigned user set to Pratik
    • State changed from new to incomplete
    • Tag set to activerecord, patch, tested

    I don't think we need a new validation method here. Could just add a new key to validates_format_of

    validates_format_of :permalink, :without => /admin/i
    

    August 3rd, 2008 @ 02:52 PM

  6. Elliot Winkler
    Elliot Winkler

    I think validates_format_of :permalink, :not => /admin/i reads a bit better. We ended up patching Rails a while back to support this, so I've prepped this into a proper patch, complete with tests, which I've attached.

    June 29th, 2009 @ 05:11 AM

  7. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activerecord, patch, tested to activerecord, bugmash, patch, tested

    August 7th, 2009 @ 02:16 PM

  8. Peer Allan
    Peer Allan

    Verified that the patch does not apply to 2-3-stable or master. The patch would have to be manually redone for master due to the refactor to ActiveModel

    August 10th, 2009 @ 02:08 AM

  9. Peer Allan
  10. Peer Allan
    Peer Allan

    Patch for master with tests, integrated into ActiveModel

    August 10th, 2009 @ 03:49 AM

  11. Rizwan Reza
    Rizwan Reza
    • Tag changed from activerecord, bugmash, patch, tested to activerecord, bugmash, patch

    not reproducible

    +1 I really like the feature.

    I am having problems implementing this to current master. The file to implement this activerecord/lib/active_model/validations/format.rb.

    August 10th, 2009 @ 03:56 AM

  12. Elliot Winkler
    Elliot Winkler

    Are all validations in ActiveModel, is that how it works now?

    August 10th, 2009 @ 02:38 PM

  13. Elliot Winkler
    Elliot Winkler

    Also I believe Peer meant for the first patch to apply to 2-3-stable and the second to apply to master since I'm guessing ActiveModel has been finished out more in master.

    August 10th, 2009 @ 02:47 PM

  14. Peer Allan
    Peer Allan

    That is exactly right, Elliot. The refactor to ActiveModel meant 2 patches, one for 2-3-stable (the first one) and one for master (the second one).

    August 10th, 2009 @ 03:18 PM

  15. Pratik
    Pratik

    I don't think this belongs to 2.3. I've applied it to the master using :without option.

    Thanks!

    August 10th, 2009 @ 03:26 PM

  16. Repository
    Repository
    • State changed from incomplete to resolved

    (from [cccb0e6b9327fb562b72007a012933c9c61a33fa]) Add validates_format_of :without => /regexp/ option [Elliot Winkler, Peer Allan]

    [#430 state:resolved]

    Example :

    validates_format_of :subdomain, :without => /www|admin|mail/
    

    Signed-off-by: Pratik Naik pratiknaik@gmail.com
    http://github.com/rails/rails/commit/cccb0e6b9327fb562b72007a012933...

    August 10th, 2009 @ 03:29 PM