validates_numericality_of with greater_than* less_than* simply don't work

It seems that the validations for:

greater_than greater_than_or_equal_to less_than less_than_or_equal_to equal_to odd even

Simply do not work (Rails 2.0.2). I've tried every combination I can think of and these never seem to fire.

How exactly did you use it?

Here's a sample

validates_numericality_of :attribute, :greater_than => 300

I've tried it multiple ways, including the very simplest like you've shown. Nothing seems to work.

Here are two exact lines:

validates_numericality_of :monthly_service_charge, :greater_than_or_equal_to => 0, :message => "must be greater than zero"

validates_numericality_of :count_sheets_per_week, :greater_than => 0, :only_integer => true, :allow_nil => true, :message => "must be greater than zero"

What's the message you get? Have you tried in console? Did you have rails 2.0 installed? What's your version of ActiveRecord then?

I try to do model.valid? and I get true even though the values have been set to something invalid (like a negative number).

Rails 2.0.2

How do I find the ActiveRecord version?

What do you see after running `gem list`?

activerecord (2.0.2, 1.15.3) rails (2.0.2, 1.2.3)

Is this the problem? I have an outdated ActiveRecord?

It looks like I have a few outdated things, but ActiveRecord is not among them:

mongrel (1.0.1 < 1.1.4) actionwebservice (1.2.3 < 1.2.6) rake (0.7.2 < 0.8.1) net-sftp (1.1.0 < 2.0.0) gem_plugin (0.2.2 < 0.2.3) cgi_multipart_eof_fix (2.1 < 2.5.0) net-ssh (1.0.10 < 2.0.1) daemons (1.0.5 < 1.0.10) capistrano (1.4.1 < 2.3.0) fastthread (1.0 < 1.0.1)

Unless there is something hidden in one of these.

I might be onto something When I do a complete update of everything, actionwebservice triggers an update of activerecord from 1.15.3 to 1.15.6.

We'll see what happens after this.

Bingo. That fixed it. Thanks for your help! I'll know to keep my gems up to date now.

I was wrong. After all of the updates it still isn't working. :frowning:

This is vexing and frustrating.

I cannot even seem to get the debugger going to try and walk into things and see what's happening.

I was wrong. After all of the updates it still isn't working. :frowning:

This is vexing and frustrating.

I just tried validates_numericality_of with greater_than and it worked
fine. What are you doing (I saw some model definitions in a previous
post of yours), what is the interaction with the model where it's


It seems that there was something in my project that was keeping it using an older version of rails.

RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION

I've commented that out. The project is now update to date. All gems are up to date. These validations now are working. But now rake test:units is failing with a "uninitialized constant CreateFeedbacks". This must be a different problem so I'll keep digging.

That's simply because you created the app with rails 1.2.3. You need to upgrade to rails 2.0.2. What you have in gem and what you have in apps may be different.