Reputation: 7461
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
Upvotes: 2
Views: 5635
Reputation: 9850
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.
Upvotes: 2
Reputation: 815
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.
Upvotes: 0
Reputation: 2584
I believe this is the answer you're looking for:
Fully custom validation error message with Rails
Upvotes: 1