Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:34:46+00:00 2026-06-04T19:34:46+00:00

I have the following validation in my model ( User ): validates :first_name,:length =>

  • 0

I have the following validation in my model ( User ):

  validates :first_name,:length => {:minimum => 2,:maximum => 50},:format => { :with => /[a-zA-Z]+/ }

I have the following in my yml locales file:

 attributes:
   first_name:
     too_short: "First name is too short"
     too_long: "First name is too long"
     invalid: "First name is not valid"

Now, if I start a rails console, and write the following:

a = User.new
a.valid?
a.errors.full_messages

I will see the following errors:

["First name First name is too short", "First name First name is not valid"]

As you can see, the attribute name is also prepended to the field error. So far, everywhere in my code, I have used model.errors[:field], and this will always show me the string I have in the yml file, but I’d like to change the strings to:

 attributes:
   first_name:
     too_short: " is too short"
     too_long: " is too long"
     invalid: " is not valid"

And use the full_messages version. The problem is, I don’t know how to translate the attribute name. Let’s say for example, that I’d like instead of First name, to have Name first. How would I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:34:48+00:00Added an answer on June 4, 2026 at 7:34 pm

    You can find the answer here http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models

    in your config/locale/(your_lang).yml

    en: 
      activerecord:
        models:
          user: Dude
        attributes:
          user:
            first_name: "Name first"
    

    change “en:” with the language symbol that you need to use

    cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following validation in a model: validates_length_of :description, :minimum => 2, :on
In a model say Task , I have following validation validates_presence_of :subject, :project, :user,
I have a User and a Gallery model and the following associations: gallery.rb attr_accessible
I have the following in my user model attr_accessible :avatar, :email validates_presence_of :email has_attached_file
I have the following model: class mark(models.Model): title=models.CharField(max_length=35) url=models.URLField(max_length=200) user=models.ManyToManyField(User,blank=True) and then I use
I have a model class that uses a custom validator as shown in following
I have the following script validation.php <?php if(!isset($_SESSION['userId'])){ session_destroy(); header('Location: home.php'); exit; } ?>
I have the following code validation php script: if(empty($_POST['captcha_code'])) { $error = 1; $code[3]
I have been following the validation for Entry boxes from here . The code
I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.