Skip to content

Instantly share code, notes, and snippets.

@lightscalar
Created December 24, 2009 15:38
Show Gist options
  • Save lightscalar/263237 to your computer and use it in GitHub Desktop.
Save lightscalar/263237 to your computer and use it in GitHub Desktop.
Just discovered this: an easy way to humanize the attributes of a model. Allows you to rename the database column name to something more reasonable. Makes for nicer, more understandable error messages back to the user.
class User < ActiveRecord::Base
HUMANIZED_ATTRIBUTES = {
:user_email => "E-mail address"
}
def self.human_attribute_name(attr)
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment