In Rails, how would I include a section of a page only if the rest of the page doesn't match a certain regexp?
Posted
by
Simon
on Stack Overflow
See other posts from Stack Overflow
or by Simon
Published on 2011-01-04T15:55:00Z
Indexed on
2011/01/04
17:54 UTC
Read the original article
Hit count: 190
ruby-on-rails
|google-adsense
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?
© Stack Overflow or respective owner