This post originated from an RSS feed registered with Ruby Buzz
by Edgar Gonzalez.
Original Post: Rails - validates_unlike plugin : validate that an attribute doesn't match against a RegExp
Feed Title: La Cara Oscura del Desarrollo de Software
Feed URL: http://www.lacaraoscura.com/feed/
Feed Description: Our experiences day after day about software development: programming languages, standards, design patterns, tools and tips.
(blog in spanish)
(versión en español)
Working in rubycorner.com, I found myself needing to validate that a model attribute didn't match against some RegExp.
My first approach was to define a validate method in my model:
def validate
if my_field =~ /html|http|onclick|onmouseover/
errors.add("my_field", "should not contain html, http, onclick or onmouseover.")
end
end
But this approach is not DRY, so I create [...]