In Rails, how would I include a section of a page only if the rest of the page doesn't match a certain regexp?
- by Simon
We have a site with a lot of user-generated content, and we'd like to show Google ads on it. Some of the content is such that we mustn't show the ads on pages containing that content, or else the whole site gets banned. We've come up with a regexp which we think will match all the offending content.
So, three approaches come to mind:
Render the page once without the ad section, and then insert the ad section into it if it's clean
Render the page as normal, and do the insertion in client-side javascript
Render the page above the ad section, capturing only the parts of the page that change; make sure there are no changing parts afterwards. Only show the ads if the captured text is clean, and make sure the unchanging, uncaptured parts are well-vetted in advance.
The first one seems like it might delay the page rendering for too long; the second seems like it might delay showing the ads too long; and the third seems too fragile. Is there a better approach? If not, which one is the best solution of the three?