rails forms base error messages -


reading rails guide says change base error message can append new base errors array. reason doing result in 2 error messages rather 1 , not expected, have in code

validates :tawme, :start_date, presence: true def tawme   errors[:base] << "buyaka!" end 

however when there error message on form get

the form contains 2 errors buyaka! start date can't blank 

i expecting "start date" replaced "buyaka!" since new base.

you should remove :start_date method arguments , add call if start_date.blank? in method tawme this...

validate :tawme def tawme   errors[:base] << "buyaka!" if start_date.blank? end 

note removed 's' per rails validation method. validates becomes validate.

in code, still included validates_presence_of(start_date).

furthermore, errors[:base] array not replacing.

the << method pushes string on end of array in errors hash.

helpful... http://guides.rubyonrails.org/active_record_validations_callbacks.html#custom-methods


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -