Error messages

Hi,

I can validate and pop up error messages using, validates_presence_of
:txt_field .But how do I change the error message from this:

1 error prohibited this abc form from being saved

There were problems with the following fields:

* Txt field can't be blank

Into this:

1 error prohibited this abc form from being saved

There were problems with the following fields:

* Text field can't be blank

Can anyone help me resolve this? Thanks

Correctly name your fields in the first place?

On Jan 21, 2008 1:50 PM, user splash [email protected]
wrote:

  • Txt field can’t be blank

Can anyone help me resolve this? Thanks

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Ryan B. wrote:

Correctly name your fields in the first place?

On Jan 21, 2008 1:50 PM, user splash [email protected]
wrote:

  • Txt field can’t be blank

Can anyone help me resolve this? Thanks

Hi,

Can I change without correcting my field names?

Thanks

          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”


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Ryan B. wrote:

          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”

user splash wrote:

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”

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!

Cheers,
Gary.

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 

can’t be empty"

Regards

Abirami.s

Try Something like this: (this one is for testing the uniqueness of a
‘name’ field, but can be adapted to whatever…)

before_validation_on_create ‘self.class.validates_uniqueness_of :name,
:message=>“You can use #{self.name}, it’s gone!!!”’

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

_jan

On Feb 1, 11:08 am, Mr Horse [email protected] wrote:

before_validation_on_create ‘self.class.validates_uniqueness_of :name,
:message=>“You can use #{self.name}, it’s gone!!!”’

It really sucks that we have to resort to hacks for stuff like this.
This is begging for a patch or plugin…


Justin B.
http://mega.blaix.com

You mean begging someone else to make a patch or plugin, right?

RSL