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 …
-
Is it possible to combine other validation rules to simulate
“allow_blank”?
-
If #1 is not possible, is it possible to write a plugin that would
allow me to use the “allow_blank” directive?
Thanks, - 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
[email protected] 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 …
- Is it possible to combine other validation rules to simulate
“allow_blank”?
Add option
:if => proc { |m| !m.blank? }
–
We develop, watch us RoR, in numbers too big to ignore.
On 19 Mar 2008, at 21:53, [email protected] wrote:
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 C. 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.
–
We develop, watch us RoR, in numbers too big to ignore.
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?
My bad, and it’s not even 4 in the morning. Thanks for the follow-up,
Fred. Works great, - Dave
On Mar 20, 12:25 pm, Frederick C. [email protected]
On 20 Mar 2008, at 17:14, [email protected] wrote:
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?
Have you tried
:allow_nil => true
? I use that on 1.2.x and 2.0.2.
Peace,
Phillip