Change error field name in Rails

The general practice now-a-days is to edit your locals like so:

# config/locales/en.yml
en:
  activerecord:
    attributes:
      user:
        fname: "First Name"

Your error message will now say “First Name can’t be…”

For completeness sake, you have another option. Which is to add the following to your User Model:

class User < ActiveRecord::Base

  HUMANIZED_ATTRIBUTES = {
    :fname => "First Name"
  }

  def self.human_attribute_name(attr, options = {}) # 'options' wasn't available in Rails 3, and prior versions.
    HUMANIZED_ATTRIBUTES[attr.to_sym] || super
  end

end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)