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 Bigg posted. "Txt field
Text field can't be empty"
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 Bigg 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!
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|
# display message only
end