1

I have a discussion board, and users can post comments on the board. But to cut down on spam, I am looking for a way to replace any URLs or Email addresses the users put in the text area with something like 'forbidden'. or even just removing them entirely.

I don't really have a clue where to start, so even something as a direction would help greatly. I was thinking of using Regex somehow, or I thought I recalled there's something in Rails already that .restricted or .constrained different things in a text area.

Thanks..

James F
  • 916
  • 2
  • 11
  • 19

1 Answers1

1

You should use ActiveRecord callbacks to check the comments before they're saved in the DB. Look here for examples (like before_validation or before_save to replace), and use Regex to replace the forbidden content.

Do not try to remove fordidden words in the JavaScript of your page, that's not a good solution: it can be easily bypassed by the user.

Baldrick
  • 23,882
  • 6
  • 74
  • 79
  • Thank you! This answer now raises the question: http://stackoverflow.com/questions/9098591/removing-email-address-using-regex-and-before-save – James F Feb 01 '12 at 15:35