Hello, 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] {2,5}(([0-9]{1,5})?\/.*)?/, :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? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You cannot access params in model. On 8/7/07, Mindtonic <mindtonic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > 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] > {2,5}(([0-9]{1,5})?\/.*)?/, > :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? > > Thanks! > > > > >-- Cheers! - Pratik http://m.onkey.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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: /(((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9] {1,5})?\/.*)?)*/ Thanks. On Aug 7, 1:36 pm, Pratik <pratikn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You cannot access params in model. > > On 8/7/07, Mindtonic <mindto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hello, > > > 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] > > {2,5}(([0-9]{1,5})?\/.*)?/, > > :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? > > > Thanks! > > -- > Cheers! > - Pratikhttp://m.onkey.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---