Hi I want to add some validation to my ruby site, and I want to stop my users putting in certain words for example dugs or stolen. I know ruby has validation commands and I was wondering if there was one for textbox input or would I have to make my own? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alan Red wrote:> I want to add some validation to my ruby site, and I want to stop my > users putting in certain words for example dugs or stolen. I know ruby > has validation commands and I was wondering if there was one for textbox > input or would I have to make my own?You could add something like an observer to your form input constantly checking for bad words, but that would be costly for large input fields and wouldn''t catch someone feeding data to the action receiving the form data directly. These things are best put into the model. Say you had a model Advert with attribute "body" which you wanted to protect, then use: validates_exclusion_of :body, :in => %w(dugs stolen), :message => "bad word used" For more general checking (for example to include case insensitive checking) override the #validate method: http://api.rubyonrails.com/classes/ActiveRecord/Validations.html#M001316 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Bush wrote:> Alan Red wrote: >> I want to add some validation to my ruby site, and I want to stop my >> users putting in certain words for example dugs or stolen. I know ruby >> has validation commands and I was wondering if there was one for textbox >> input or would I have to make my own? > > You could add something like an observer to your form input constantly > checking for bad words, but that would be costly for large input fields > and wouldn''t catch someone feeding data to the action receiving the form > data directly. > > These things are best put into the model. Say you had a model Advert > with attribute "body" which you wanted to protect, then use: > > validates_exclusion_of :body, :in => %w(dugs stolen), :message => "bad > word used" > > For more general checking (for example to include case insensitive > checking) override the #validate method: > > http://api.rubyonrails.com/classes/ActiveRecord/Validations.html#M001316Works perfectly, thanks for the help - surprising how straight forward that is to code really. Ruby on rails real is much easier than I believed. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---