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.


source to share

3 answers

I believe this is the answer you are looking for:

Complete authentication error message with Rails



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
    format: '%{message}'


AFAIK, you cannot do this for a single attribute.



I searched for the same question and stopped:



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.



All Articles