Making Validations Optional


I am working with URL validations. I want this validation to be
optional if the data exists in the form submission. I have tried
several things.

validates_format_of :website,
        :if => params[:organization][:website],
        :with => /((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]
        :message => "Please enter a valid url"

Of course the challenge is in the :if statement

I won't bother you guys with all of my experiments, but I have tried
using :website, :website.length > 0, params[:organization][:website]
and creating a method in my organization class. None of these have
worked. What am I missing?


You cannot access params in model.

Ahhh... so I was barking up the wrong proverbial tree.

The solution to the problem lay in the REGEX code. I simply added a
test for zero or one instance at the end: