validates_presence_of :text_field,:message=>"Text field
can’t be empty"
I thought that would display it as “txt field Text field can’t be empty”
–
Hi,
I’ve tried the suggestion, validates_presence_of
:text_field,:message=>“Text field can’t be empty”, posted by Abirami
Selvam (abirami). The results are just as Ryan B. posted. “Txt field
Text field can’t be empty”
I’ve tried the suggestion, validates_presence_of
:text_field,:message=>“Text field can’t be empty”, posted by Abirami
Selvam (abirami). The results are just as Ryan B. posted. “Txt field
Text field can’t be empty”
You can use a custom validation method:
def validate
errors.add_to_base(“Text field can’t be empty”) if txt_field.blank?
end
or you could perhaps use a virtual field call text_field and translate
between the two, but all this seems well overcomplicated compared to
just renaming the field!
Hi,
whether you have to change your error message content or the field
name…
1. you can change the name of the text field as text_field
(or)
2. you can add the message like
validates_presence_of :text_field,:message=>"Text field
Correctly name your fields in the first place? rubbish.
In my case I just need error messages in a different language (geman).
I can’t name database columns using german words (at least not in all
cases like with umlauts).
I add :message=>“Text field can’t be empty” to my validation and then
display errors like this: @object.errors.each do |field,message|