Ror Apps And Thl Wiki Links

THL Toolbox > Developers' Zone > Ruby On Rails Development > RoR Apps and THL Wiki Links

RoR Apps and THL Wiki Links

Contributor(s): Jed Verity (jev3a@virginia.edu)

Additional links on using Wiki pages in THL:

Within the context of the main THL site, showing content from Collab within THL pages requires cross-domain transfers, so the pages make ajax requests to a local PHP script called wiki_reader.php that first reads the wiki content and then presents it to the Javascript. Rails apps, however, are on different subdomains from the main THL site, meaning that calls to that same wiki_reader script are cross-domain requests and thus don't work.

This can be remedied by the fact that Rails apps and the main site share the same root domain (currently thlib.org), allowing wiki functionality by means of the Javascript document.domain property and iframes. In other words, both the Rails app and wiki_reader.php specify their document.domain to be "thlib.org" anywhere in their Javascript code blocks. Given that Rails apps call the THL Javascript framework through the thdl_integration plugin, the document.domain property is set in the jquery.thdl.js script and thus becomes part of every Rails app page.

Then, in class_external.js, where the wiki ajax happens, the DoAjax function has been modified to look for the presence of "tmb" or "places" in the hostname (so this will eventually need to be modified to look for other Rails app signifiers, and should in fact be broken out into a universal function, since multiple functions look for this), and if found, instead of looking for wiki_reader.php locally and ajaxing in content from there, it creates a hidden iframe to call wiki_reader.php. Since the document.domain property will be the same for the parent and iframe documents, the DOM of the child document can be read directly by the parent, which just pulls the iframe document content over into its #content div.

It goes without saying that this solution will not work if the Rails app does not have the same root domain (thlib.org or whatever) as the main THL site.

Provided for unrestricted use by the external link: Tibetan and Himalayan Library