How to remove field names in validates_presence_of on rails Model

How to remove field name in validates_presence_of on rails Model for next encoding

validates_presence_of :address, :attributes => true, :discard_if => :invalid?, :on => :save, :message=> "Invalid Address"

      

and Output -

Address Invalid address  

      

and I don't want the address field in this check

Please help me to solve this problem.

+2


source to share


3 answers


I believe this is the answer you are looking for:



Complete authentication error message with Rails

+1


source


Standard error format "%{attribute} %{message}"

. If you don't want the attribute names to be included in messages, you can change them errors.format

in your locale.

# config/locales/en.yml
en:
  errors:
    format: '%{message}'

      



AFAIK, you cannot do this for a single attribute.

+1


source


I searched for the same question and stopped:

*instance.errors.add*

      

for exmpl,

question.errors.add("Answer","can't be blank") if self.body.blank?

      

There is * errors.add_to_base *, but just adding works more comfortably in my opinion.

0


source







All Articles