Reemplazo y restricción de correos electrónicos y URL en el área de texto

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.


preguntado el 01 de febrero de 12 a las 14:02

1 Respuestas

You should use ActiveRecord callbacks to check the comments before they're saved in the DB. Look aquí 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.

Respondido 01 Feb 12, 18:02

Thank you! This answer now raises the question:… - James F

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.