Master ruby with us


Posted by firstruby on January 21, 2011

In earlier version of Ruby on Rails 3, if we have some column like “dept_date”, in that case, error message is displayed as,


Dept date can’t be blank.


To change field/attribute name, we have to humanize this field. To humanized this field to display like “Departure Date” instead of “Dept date”  in earlier version of Rails 3 (i.e, in Rails 2 .x), then need to write like following,

:dept_date => “Departure Date”

def self.human_attribute_name(attr)
HUMANIZED_ATTRIBUTES[attr.to_sym] || super

In Rails 3, “def self.human_attribute_name(attr)” changes to “self.human_attribute_name(attr, options={})”, so above function will be as,


def self.human_attribute_name(attr, options={})
HUMANIZED_ATTRIBUTES[attr.to_sym] || super


Due to above code, dept_date field will be humanized to ‘Departure Date’.


2 Responses to “HUMANIZED_ATTRIBUTES in Rails 3”

  1. lbfromla said

    Thank you, firstruby!

  2. Sasidaran said

    Thanks a lot, first ruby !!!!!!!!!!!!!11

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: