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

Jake C. wrote:

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

Thank you!

Jake

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.
jp

On 9/21/06, Jeff P. [email protected] 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

Jake C. wrote:

X-Google-AttachSize: 996

On 9/21/06, Jeff P. <[email protected]> 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–

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

There at railsconf europe about reusing bits of rjs.
In a nutshell a reasonable way of doing things is via helper functions,
a little like so (recalling this from memory):

def common_fragment
update_page do |page|
page.whatever
end
end

Then in your rjs files do
page<<common_fragment()

Fred

Fred wrote:

There at railsconf europe about reusing bits of rjs.
That should of course say ‘There was a talk at railsconf europe’ (by
Marcel Molina Jr. slides from talk available at
http://project.ioni.st/images/uploads/EuroRailsConf.pdf)

Fred

On 9/21/06, Fred [email protected] wrote:

end

Then in your rjs files do
page<<common_fragment()

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

Thanks again!
Jake