Validates_numericality_of with greater_than* less_than* simply don't work

It seems that the validations for:


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,
=> 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”

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’s the message you get? Have you tried in console? Did you have
rails 2.0 installed? What’s your version of ActiveRecord then?

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.

What do you see after running gem list?

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

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.

On 17 May 2008, at 19:15, ccuilla wrote:

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


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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs