Error messages

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

Ryan Bigg 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 Bigg posted. "Txt field Text field can't be empty"

user splash wrote:

Ryan Bigg 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 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!

Cheers, Gary.

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

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

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

RSL