# .rjs templates undesiered output problem

**URL:** <https://www.ruby-forum.com/t/rjs-templates-undesiered-output-problem/60801>\
**Category:** Rails\
**Created:** [May 17, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/rjs-templates-undesiered-output-problem/60801 "2006-05-17T17:00:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Leo](https://www.ruby-forum.com/u/Leo)\
**Post date:** [May 17, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/rjs-templates-undesiered-output-problem/60801/1 "2006-05-17T17:00:42Z")

</div>

Hello everyone, I am working with rjs templates in rails, and I’m amazed  
of how simple it is to generate code with ajax, however I’am having some  
troubles and I can’t seem to find a way to solve’em.

Whenever I put some code in the template, let’s say:

```
 page.visual_effect :highlight, 'sitio37', :duration => 3

```

I get the desiered highlight allright, but, I also get the autogenerated  
javascript code that makes it happen printed on screen, like so:

```
new Effect.Highlight("sitio37",{duration:3}); } catch (e) { 

```

alert(‘RJS error:\n\n’ + e.toString()); (that is, it highlights the  
item, but it also prits the code on the left)

This very simptom, I also get with other insertions and effects, I’m  
even using a partial on the template, and it’s rendering it 3 times  
(being the two firs in java code and the last in proper dhtml).

I’ve been searching for a way to avoid this undesiered output (as I’ve  
desided to name it), if anyone can help it would be great.

Any help is thanked in advance,  
Leo  
studio.st

---

<div class="post-metadata">

**Author:** ![Leo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Leo](https://www.ruby-forum.com/u/Leo)\
**Post date:** [May 17, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/rjs-templates-undesiered-output-problem/60801/2 "2006-05-17T17:21:46Z")

</div>

It could be an encoding problem, do you have filters in your controller  
that alter the content-type headers?

Cheers

## Jonathan

http:/www.agileevolved.com

---

<div class="post-metadata">

**Author:** ![Leo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Leo](https://www.ruby-forum.com/u/Leo)\
**Post date:** [May 17, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/rjs-templates-undesiered-output-problem/60801/3 "2006-05-17T17:42:22Z")

</div>

Well, not really. Controlers and helpers are normal, no header or  
encoding mod’s.  
The closest thing I’ve found about anything resembling this, is the  
[http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html](http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html)  
I supose putting script tags would be one solution, but none of the webs  
that  
have published about .rjs templates implement something like this.

I’m thinking configration issues, but who knows.

Leo

---

<div class="post-metadata">

**Author:** ![Leo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Leo](https://www.ruby-forum.com/u/Leo)\
**Post date:** [May 17, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/rjs-templates-undesiered-output-problem/60801/4 "2006-05-17T22:47:17Z")

</div>

Ok, finally, thanks to Cody at [http://www.codyfauser.com](http://www.codyfauser.com)

I have finally solved the problem.

It was a quite a silly issue tu be honest, but i’ll settle it here.  
The thing is, before using rjs templates I had a normal remote\_form\_tag  
with all of it’s ingredients:

> \<%= form\_remote\_tag(:update =\> “divid”  
> :url =\> { :action =\> :create },  
> :position =\> “top”,  
> :success =\> %(Element.hide(‘ajxform’)) ) %\>

My problem was, that when I started using rjs templates, I didn’t  
realize that the update param (:update =\> “divid”) was generating extra  
prints on the screen.  
Solution:

> remove the update param alltoghether, and its working like a charm.

My fault people, I didn’t see that one, sorry for taking up your time.

I put it here to help any other hwo runs into the same trouble.

Leo

---

<div class="post-metadata">

**Author:** ![Leo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@Leo](https://www.ruby-forum.com/u/Leo)\
**Post date:** [May 17, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/rjs-templates-undesiered-output-problem/60801/5 "2006-05-17T20:30:10Z")

</div>

The object page that is generated implicitly when we access de .rjs  
template, de ActionView doc says that this page object its implicitly  
wraped around an “update\_page” block, it also says that update\_page\_tag  
is exacltly like update\_page only it wraps the generated code around  
scrtpt tags, so I figured to change the code above code to:

> update\_page\_tag {  
> page.visual\_effect :highlight, ‘sitio’ + @sitio.id.to\_s, :duration =\> 3  
> }

And it does the same exact thing, I get the highltighted item, and I  
also keep getting the generated Javascript code rendered right into the  
screen.
