I’ve never taken the time to package/release/announce this plugin of
have I? Forgive me. The time has come.
I introduce to you Semantic Attributes!
From the README:
The method-chained validation routine built into ActiveRecord must die!
time for an object-oriented approach to attribute validations. The
Attributes plugin provides this approach by letting you attach
your attributes with a tasty DSL. These predicates package up some
sweet behavior, where validations are really only the beginning. I’ve
discovered that it can be really useful to use these predicates to
between human and machine formats: for example, with the phone number
predicate you can let your users enter phone numbers with whatever
formatting they want, always save the values to the database as numeric
strings, and then present the values back to the user with standard
I’ve also found other nifty uses for object-oriented predicates that
up validation. For example, it becomes easy to run a quick validation
on a field with a sample value and report true/false. This is exactly
the expected_error_for(:field, value)> method does, and it lets you
validation routine that listens to form data as it’s being typed and
problems without duplicating your validation code client-side. In a
vein, the _valid? attribute suffix lets you do single-attribute
on a record anytime you want.
For more, see:
and of course:
p.s. this is completely compatible with ActiveRecord validations … you
use 'em both if you want