Forum: Ruby on Rails Dynamic text highlighting

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tomas F. (Guest)
on 2007-04-28 16:51
Hi,

consider following situation:

I want to load an external site A.html in an iframe. As far, no problem.

But now, I want to load it with words hightlighted on it, like Google's
cache result pages. Unfortunately, the decision, which words should
highlighted is done on run time.

Is it possible to replace the original content with my content on the
fly?

Thanks.

Best regards,
Tomas
Andrew S. (Guest)
on 2007-05-01 16:54
(Received via mailing list)
On 28 Apr 2007, at 13:51, Tomas F. wrote:
> I want to load an external site A.html in an iframe. As far, no
> problem.
>
> But now, I want to load it with words hightlighted on it, like
> Google's
> cache result pages. Unfortunately, the decision, which words should
> highlighted is done on run time.
>
> Is it possible to replace the original content with my content on the
> fly?

Yes, you can do that if you route the request/response through your
Rails app.

E.g. in your index action, make a Net::HTTP request to your external
site, gsub the response's body to your heart's content, then send the
end result to the browser.

If you want the user to be able to navigate around the external site,
you'll have to rewrite all the hyperlinks so that they point back to
your own action, with the real path stored in a param somewhere, so
your action can make another HTTP request to the appropriate part of
the external site, gsub the response's body (including hyperlinks)
and send the result to the browser.

Regards,
Andy S.
This topic is locked and can not be replied to.