conditional validation in rails.....awesome.
July 16th, 2007
came across a little challenge the other day about how to validate a field in a form. basically i have a link field that should be validated to make sure that there are no spaces and that it contains http:// in the address. of course this can be easily done by doing validates_presence of and a validates format of by matching the string. however, how about when you link could be a embedded video from youtube or some other video sharing site? easy, skip the validation by doing a condition like so:
cant remember off hand but something like this
validates_presence of :link, if => :check_link?
def check_ling? return true if whatever here…. end
for more info check out http://railscasts.com/episodes/41