Monday, 15 February 2010

validation - rails validates : message when it not passed? -



validation - rails validates : message when it not passed? -

with rails can set message validates "format:", "inclusion:" "exclusion:"...

but how can write global message error when validates not passed?

":message" does't works in validates hash key.

this outside scope of format validators provided rails. this, can write own custom validator fits purpose, or inline method validation so:

class mymodel < activerecord::base validates :correct_format? def correct_format? errors.add(:some_attribute, 'generic message') unless some_attribute =~ /[a-z]/ end end

ruby-on-rails validation

No comments:

Post a Comment