Forum: Ruby on Rails validating when form labels don't match table fields

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B1835ed055e04fdfc1111944218807ce?d=identicon&s=25 Mike Poirier (Guest)
on 2007-01-01 04:58
(Received via mailing list)
Hi,

I have a model where the attribute names don't match exactly what I'd
like to use for labels for the input s on my view.  For example, my
model order has an attribute "ordered_by_first_name" and I'd like the
label on the view to be "Your first name".  Fine.  Except that if I use
really nice validation helpers I can't fully override the error
message.  I can use :message but it always sticks in the model
attribute name.  This will cause some confusion and I was hoping to
make things a little more user friendly on the view.

My order model has other attributes that refer to people's names in
them (no, I'm not entirely normalized).

I guess it goes without saying that I was hoping to use
error_messages_for in the view.

Anyone have any suggestions for when the model names don't match what
you'd want to present to a user?

TIA,
Mike
B0f09f622c913a13b9bfd332fca56563?d=identicon&s=25 Dan Manges (Guest)
on 2007-01-01 18:47
(Received via mailing list)
Mike Poirier wrote:
> Anyone have any suggestions for when the model names don't match what
> you'd want to present to a user?

If you use a custom validation you can use:
self.errors.add_to_base("full message") to specify a full message.  I
am not sure how to override the attribute name for the default error
messages.

Dan Manges
This topic is locked and can not be replied to.