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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:50:24+00:00 2026-05-27T23:50:24+00:00

I am trying to write a rails application the involves geographic lat and long

  • 0

I am trying to write a rails application the involves geographic lat and long values and I’ve written a validation for this below:

validates :latitude, numericality: {greater_than_or_equal_to: -89.9999, less_than_or_equal_to: 89.9999}, allow_nil: true

Note: latitude and longitude are decimal values with precision: 6 scale: 4 and precision 7 scale: 4 respectively. (Latitude goes from -90 to 90 (exclusive) and longitude goes from -180 to 180 (inclusive))

However, this code is passing -90 and 90 respectively when it should in fact fail. Does numericality validation take more than 1 arguments as used above? How would I write this validation properly?

Thank you.

EDIT: I have taken a look at the documentation for the validator and it only checks for:

{ :greater_than => :>, :greater_than_or_equal_to => :>=, :equal_to => :==, :less_than => :<, :less_than_or_equal_to => :<=, :odd => :odd?, :even => :even? }

So I assumed that the way I used it above would work.

  • 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-05-27T23:50:24+00:00Added an answer on May 27, 2026 at 11:50 pm

    I’m not able to reproduce this problem:

    # Code
    
    require 'rails'
    
    class Testing
      attr_accessor :number
      include ActiveModel::Validations
    
      validates :number, numericality: {
        greater_than_or_equal_to: -89.999, less_than_or_equal_to: 89.999
      }
    end
    
    [89, 89.999, 90, 90.001].each do |n|
      t = Testing.new
      t.number = n
      puts "#{n} valid: #{t.valid?}"
    end
    
    # Output
    
    89 valid: true
    89.999 valid: true
    90 valid: false
    90.001 valid: false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to write a validation for Rails to ensure that a price
I am trying to write a simple integration test on a Rails 3.1 application
I am trying to write a sproutcore frontend for a rails 3.1 application I
I have the following in my Rails 3 controllers/application.rb (which I'm trying to write
I'm trying to write an app using Ruby on Rails and I'm trying to
I'm trying to write an import rakefile for Redmine. It uses ruby on rails.
I'm trying to write an equivalent of Rails data model evolution/rollback mechanism using Spring
I'm trying to write a Ruby class that works similarly to Rails AactiveRecord model
I am currently trying to learn Ruby On Rails as I am a long-time
I'm trying to write and use a custom filter for Solr. The parent application

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.