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

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -