Created
October 14, 2011 17:07
-
-
Save dcoder2099/1287689 to your computer and use it in GitHub Desktop.
using i18n to present human-friendly AR model names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the purpose of this query, assume that there is an ActiveRecord model with an attribute (db column) with the name 'obscure_field'. | |
In the AR class is the following validation call: | |
validates_presence_of :obscure_field, :message => 'is necessary' | |
However, in the view, this field is labeled as "Meaningful Field": | |
(formtastic syntax) | |
<%= f.input :obscure_field, :label => 'Report type', :required => true %> | |
When validation executes and errors are displayed, the message is: | |
"Obscure field is necessary" | |
How can I get the field to validate as "Meaningful field" but still perform the proper field-level formatting (red box, positioned message)? | |
So, @robmack pointed out this thread http://www.ruby-forum.com/topic/196094 | |
Which has some rather obtuse discussion about overriding humanize on the model, but it turns out that down in the bowels of the thread is this gem: | |
http://www.ruby-forum.com/topic/196094#886374 | |
I18N to the rescue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment