Calling one RJS template from another

I need to call an RJS template from within another template…is there a way to do this?

Thank you!

Jake

Ok, say I have update_a.rjs and update_b.rjs. update_b.rjs has a lot of complex update logic, etc, that is used by various actions across my code. update_a.rjs in different places as well.

update_a.rjs needs to always ensure update_b.rjs is called directly after it. Rather that going around making sure every place that update_a.rjs is rendered also consequently renders update_b.rjs, I was hoping I could simply chain them in some way…

Thanks, Jake

Jake Cutter wrote:

> > I don't know of a way. Perhaps if you give us some context we can come > up with a different way to solve the problem you are working on.

Ok, say I have update_a.rjs and update_b.rjs. update_b.rjs has a lot of complex update logic, etc, that is used by various actions across my code. update_a.rjs in different places as well.

update_a.rjs needs to always ensure update_b.rjs is called directly after it. Rather that going around making sure every place that update_a.rjs is rendered also consequently renders update_b.rjs, I was hoping I could simply chain them in some way...

Thanks, Jake

------=_Part_8415_15296355.1158862352948 Content-Type: text/html; charset=ISO-8859-1 X-Google-AttachSize: 996

On 9/21/06, <b class="gmail_sendername">Jeff Pritchard</b> &lt;<a href="mailto:rails-mailing-list@andreas-s.net">rails-mailing-list@andreas-s.net</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> I don't know of a way.&nbsp;&nbsp;Perhaps if you give us some context we can come<br>up with a different way to solve the problem you are working on.</blockquote><div><br><br>Ok, say I have update_a.rjs and update_b.rjs. update_b.rjs has a lot of complex update logic, etc, that is used by various actions across my code. update_a.rjs in different places as well. <br><br>update_a.rjs needs to always ensure update_b.rjs is called directly after it. Rather that going around making sure every place that update_a.rjs is rendered also consequently renders update_b.rjs, I was hoping I could simply chain them in some way... <br><br>Thanks,<br>Jake<br></div><br></div>

------=_Part_8415_15296355.1158862352948--

You could try something like this..

def rjs_a   h = headers['Content-Type']   render :update do |page|    page << self.send("rjs_b")    @performed_render = false    headers['Content-Type'] = h   end end

Untested, but some variation on this should work. The @performed render call will prevent you from getting double render errors The header magic is sometimes required to prevent your browser from just rendering the response as text. You may not need it here.

_Kevin

I ran into this problem about a month ago. I couldn't find anyone else who had found a solution, so I rolled my own. This is a little bit messy, but I'm using in a couple place and can tell you for sure that it works. In the RJS file called first I use page.call to issue a second ajax call. Here is the rjs command I've been using:

page.call("new Function(\"new Ajax.Request('/controller/action?qrystring=" +params[:q]+"', {asynchronous:true, evalScripts:true})\")")

Hop this helps.

Regards, Aaron

Thanks for all the good suggestions guys. I liked them all, but the above appears to be the cleanest.

Thanks again!

Jake