# Using shared RJS templates

**URL:** <https://www.ruby-forum.com/t/using-shared-rjs-templates/53512>\
**Category:** Rails\
**Created:** [February 8, 2006, 1:56am UTC](https://www.ruby-forum.com/t/using-shared-rjs-templates/53512 "2006-02-08T01:56:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [February 8, 2006, 1:56am UTC](https://www.ruby-forum.com/t/using-shared-rjs-templates/53512/1 "2006-02-08T01:56:16Z")

</div>

I’ve got an action in my application controller that needs to call a  
shared RJS template. Typically it’s actually being called by subclasses  
of the application controller.

I’ve tried this…

def action  
…code…  
render :partial =\> “shared/template”  
end

with ‘\_template.rjs’ existing in the shared folder.

The problem that crops up is that it simply inserts the contents of the  
RJS template into the appropriate spot as flat text without actually  
executing the javascript.

I’m on edge rails ATM.

Anyone out there playing with RJS templates encountered this before?

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [February 8, 2006, 2:17am UTC](https://www.ruby-forum.com/t/using-shared-rjs-templates/53512/2 "2006-02-08T02:17:39Z")

</div>

Any reason you have it as a partial? RJS’s are never meant to be  
rendered to  
the screen (from what I understand), so really, there would be no reason  
to  
have them as partials. This may or may not be your problem, but try  
making  
it a regular template and see what happens.

-Nick

On 8 Feb 2006 00:54:27 -0000, Kevin O. \<

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [February 8, 2006, 4:43am UTC](https://www.ruby-forum.com/t/using-shared-rjs-templates/53512/3 "2006-02-08T04:43:06Z")

</div>

On Tuesday, February 07, 2006, at 8:17 PM, Nick S. wrote:

> Any reason you have it as a partial? RJS’s are never meant to be  
> rendered to  
> the screen (from what I understand), so really, there would be no reason to  
> have them as partials. This may or may not be your problem, but try making  
> it a regular template and see what happens.
> 
> -Nick

I finally figured this out. The link\_to\_remote calls that were calling  
the ajax action were specifying an :update parameter. When you do this,  
it replaces the contents of the target object with the javascript from  
the RJS template. Removing that parameter makes things work just fine.

BTW, leaving the render call as

render :partial=\>“shared/template”

works just fine with RJS templates, although I think it makes more sense  
to have the call look like this…

render “shared/template”

\_Kevin

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [February 8, 2006, 7:01pm UTC](https://www.ruby-forum.com/t/using-shared-rjs-templates/53512/4 "2006-02-08T19:01:53Z")

</div>

Cool, glad you got it working, and nice to know that partials do  
infact work. But as you said, the concept just seems “off” to me to  
have a partial RJS template.

On 8 Feb 2006 03:42:52 -0000, Kevin O.
