2

How to remove Field Name in validates_presence_of on rails Model for the following coding

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

and the Output is

Address Invalid address  

and I don't want Address field in this validation

Please Help me to solve this problem

Senthil Kumar Bhaskaran
  • 7,371
  • 9
  • 43
  • 56

3 Answers3

2

The standard error format is "%{attribute} %{message}". If you don't want attribute names included in messages, you can change errors.format in your locale.

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

AFAIK, you can't do this for a single attribute.

graywh
  • 9,640
  • 2
  • 29
  • 27
1

I believe this is the answer you're looking for:

Fully custom validation error message with Rails

Community
  • 1
  • 1
Delameko
  • 2,544
  • 21
  • 19
0

I was searching for the same question and stops on:

*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 add is working more comfortably, for my opinion.

TiSer
  • 775
  • 3
  • 11
  • 30