# Prerender AJAX

**URL:** <https://www.ruby-forum.com/t/prerender-ajax/176381>\
**Category:** Rails\
**Created:** [September 29, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/prerender-ajax/176381 "2009-09-29T21:56:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![timend](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@timend](https://www.ruby-forum.com/u/timend)\
**Post date:** [September 29, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/prerender-ajax/176381/1 "2009-09-29T21:56:50Z")

</div>

Hi,

I’ve got several AJAX actions in my controller and another action,  
that displays links that could trigger the AJAX calls. I’m trying to  
implement the following:

1.) Usually if the user clicks the link on the page, the AJAX request  
to the server is made, rails renders the result and sends the response  
back to the client and the response is inserted into the page.

2.) I’d like to have a simple helper method  
prerender ‘/someurl/to/some/controller/action/params/’  
and when using it in the view of the primary action, the behaviour  
should change. When the user clicks the link, no AJAX request is  
triggerred, instead the client side script fetches the result from  
some Javascript variable, like $.prerendered\_ajax[’/someurl/to/some/  
controller/action/params’] and inserts that into the page.

This would allow me to fine tune the amount of static page content and  
ajax calls to kinda balance bandwith and responsiveness.

In order for this to work of course, the server had to put in the  
result of that AJAX action into the $.prerendered\_ajax array. Question  
is now:

How do I (with the least overhead and without restarting rails  
entirely) get the result of the AJAX action inside my primary action  
as a string (and giving the url). ActionController::Base.call seems to  
be my guy, but the env parameter has holds quite a few values when  
debugging a normal AJAX call, and I’m not sure how to fill them.

Any help welcome!

T. Enderling
