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..
You should use ActiveRecord callbacks to check the comments before they’re saved in the DB. Look here for examples (like
before_validationorbefore_saveto 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.