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 8669751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:33:04+00:00 2026-06-12T18:33:04+00:00

I am currently validating my model using this code: validates :price, :presence => true,

  • 0

I am currently validating my model using this code:

validates :price, :presence => true, :numericality => {:greater_than => 0}

This works fine, except that when I do not enter any value in this field, I get 2 errors – both “Price can’t be blank” and “Price is not a number”.

I can understand why this happens – clearly it is failing both tests. But i’m wondering if there is a way to ge the validation to stop after one test, since there is no point testing if the number is > 0 if there is no number at all?

Thanks!

Edit: For clarity, I don’t want to allow the field to be blank, I just don’t want the numericality test to run if it is blank, to avoid 2 error messages for what is really 1 error.

  • 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-12T18:33:05+00:00Added an answer on June 12, 2026 at 6:33 pm

    Not sure if it will work, but you can try:

    validates :price, :presence => true, :numericality => {:greater_than => 0, :allow_blank => true }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using the validation code listed here in an application. I'd like to
I am currently using $.blur(fn();) for form validation, but this only takes effect when
Using the code below I can trap an invalid cell entry. In this simple
I am currently working on an ASP.NET MVC2 project. This is the first time
I'm using EF 4.1 Code First, and I'm making a configurable utility for parsing/importing
I'm currently using DataAnnotations to validate my MVC 2 app. However, I've ran into
I'm not interested in answers concerning client side validation or model binding. Really, this
I'm currently using an API and not a database, and I want to be
I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to
Given the following models (cut down for understanding): class Venue(models.Model): name = models.CharField(unique=True) class

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.