If a model has an attribute named "unit" for example, but in your views you refer to this attribute as "unit price", but when you do validation, error messages default to "unit", how do I modify this to say "unit price"?
+1
A:
Use localization to set the "English" name of your attribute. You can set both the singular and plural names:
en:
activerecord:
attributes:
unit:
one: Unit price
other: Unit prices
Andrew Vit
2010-08-26 07:09:23
Doesn't seem to work for me.I haven't worked on localization yet, is there anything I need to do before this would work?
fivetwentysix
2010-08-26 07:23:32
Fixed my answer: I had answered for the model name, not the attribute name.
Andrew Vit
2010-08-26 07:50:55
A:
Hi fivetwentysix
I'm not sure how you can change the column name , But following is a working workaround
in your model create a virtual attribute called unit_price
something like this
attr_accessor :unit_price
validates_presence_of :unit_price, :message => "This is a custom validation message"
def before_validation
self.unit_price = self.unit
end
cheers
sameera
sameera207
2010-08-26 07:46:52