Text validation

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

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#M001316

Works perfectly, thanks for the help - surprising how straight forward
that is to code really. Ruby on rails real is much easier than I
believed.