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

  • SEARCH
  • Home
  • 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 9169253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:49:50+00:00 2026-06-17T15:49:50+00:00

How can I code if I want the same error messages on all the

  • 0

How can I code if I want the same error messages on all the validation?

I have 3 criterias such as presence, uniqueness and length.
I want the same error message.
But my code works only when it matched with length error.
How can I apply to all(other two)?

validates :title,   
    :presence => true,   
    :uniqueness => true,   
    :length => { :maximum => 100, :message => "Must be unique, and has to be less than 100 characters"}
  • 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-17T15:49:53+00:00Added an answer on June 17, 2026 at 3:49 pm

    I’m confident that there is a way to do this using validates, but if I had this problem, I’d probably just write a custom validation:

    validate :title_format
    
    def title_format
      if title.blank? || title.length > 100 || Post.where(:title => title).exists? 
        errors.add(:title, "Must be unique and less than 100 characters")
      end
    end
    

    (Replace Post with your actual model name, naturally.)

    Incidentally, your message says ‘less than 100 characters’, but you’re actually validating ‘less than or equal to 100 characters’. You’ll probably want to pick one or the other and be consistent about it.

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

Sidebar

Related Questions

Hi can you help me with this?? I have this code and i want
I was wondering how I can detect code plagiarism with Javascript. I want to
I want to write a php code that can search for multiple keywords separated
I want to code this part of a VB6 application in c#. How can
according to this code if i want to access imageView1 and imageView2 how can
I want to know if I can create a WebBrowser through code in Vb.NET,
I want see the source code of System.Web.Routing.RouteValueDictionary class. But Reflector can't disassemble it
who can give me a simple code , i want a simplest way to
I can check for iPhone with this code: (navigator.userAgent.match(/iPhone/i)) But I want to target
I can get my page's html code during my program and what I want

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.