Rails 3 validate presence of many columns with custom messages -
Rails 3 validate presence of many columns with custom messages -
is there way specify many validations more concisely?
validates :col_a, :presence => {:message => 'col_a cannot blank'} validates :col_b, :presence => {:message => 'col_b cannot blank'} validates :col_c, :presence => {:message => 'col_c cannot blank'}
i'd settle generic message if had to.
you can give multiple field names validator
validates :col_a, :col_b, :col_c, :presence => true
you can specify multiple validators in same line.
validates :col_a, :col_b, :col_c, :presence => true, :numericality => true
the total error message contain field name. don't need add together field name prefix. if want utilize custom message then:
validates :col_a, :col_b, :col_c, :presence => {:message => "empty value found"}
ruby-on-rails ruby-on-rails-3 validation
Comments
Post a Comment