allow_blank in older version of Rails

Hi,

Our hosting company is using RoR 1.2.3. This version does not seem to
support the "allow_blank => true" validation rule. I have two
questions ...

1. Is it possible to combine other validation rules to simulate
"allow_blank"?

2. If #1 is not possible, is it possible to write a plugin that would
allow me to use the "allow_blank" directive?

Thanks, - Dave

laredotornado@zipmail.com wrote:

Our hosting company is using RoR 1.2.3. This version does not seem to
support the "allow_blank => true" validation rule. I have two
questions ...

1. Is it possible to combine other validation rules to simulate
"allow_blank"?

Add option
             :if => proc { |m| !m.blank? }

Thanks, but that didn't seem to work. When I left my "fax" field
blank, I got an error message returned from validation "Fax cannot be
blank". Here's my validation rule:

  validates_presence_of :fax, :if => proc { |m| !m.blank? }

What I would like is for the field to be allowed to be empty or nil,
but because of RoR 1.2.3 I can't use allow_blank. - Dave

Thanks, but that didn't seem to work. When I left my "fax" field
blank, I got an error message returned from validation "Fax cannot be
blank". Here's my validation rule:

validates_presence_of :fax, :if => proc { |m| !m.blank? }

What I would like is for the field to be allowed to be empty or nil,
but because of RoR 1.2.3 I can't use allow_blank. - Dave

The object that gets passed to the proc is the record itself, so you need m.fax.blank?

Fred

Frederick Cheung wrote:

The object that gets passed to the proc is the record itself, so you need m.fax.blank?

Whoops, thanks Fred. Another 4am blunder.

Thanks guys. Let me go one step further. I downloaded a
"validates_as_phone" plugin. So what I want to do is only validate
the fax field is a user has entered a non-empty value. However, right
now, this rule

  validates_as_phone :fax, :if => proc { |m| m.blank? }

doesn't kick in, even if the user has entered a value like "111". How
can I adjust the above?

- Dave

Thanks guys. Let me go one step further. I downloaded a
"validates_as_phone" plugin. So what I want to do is only validate
the fax field is a user has entered a non-empty value. However, right
now, this rule

validates_as_phone :fax, :if => proc { |m| m.blank? }

Like i said before, that needs to be m.fax.blank?

My bad, and it's not even 4 in the morning. Thanks for the follow-up,
Fred. Works great, - Dave

Frederick Cheung wrote:

Have you tried

:allow_nil => true

? I use that on 1.2.x and 2.0.2.

Peace,
Phillip