# Render :update returns js wrapped in a HTML body

**URL:** <https://www.ruby-forum.com/t/render-update-returns-js-wrapped-in-a-html-body/125364>\
**Category:** Rails\
**Created:** [January 8, 2008, 5:00pm UTC](https://www.ruby-forum.com/t/render-update-returns-js-wrapped-in-a-html-body/125364 "2008-01-08T17:00:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wepic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ccd318/32.png) [@wepic](https://www.ruby-forum.com/u/wepic)\
**Post date:** [January 8, 2008, 5:00pm UTC](https://www.ruby-forum.com/t/render-update-returns-js-wrapped-in-a-html-body/125364/1 "2008-01-08T17:00:49Z")

</div>

Hi.

From what I’m learned the below is suppose to return “alert(‘Im JS’);”  
to the javascriptGenerator that’s suppose to make the page scream ‘Im  
JS’…(?)

render :update do |page|  
page.call :alert, “Im JS”  
end

In Rails 1.2.3 it works perfectly.

BUT in Rails 2.0.2 it returns the js neatly wrapped in a full HTML-body,  
and the browser shows me nada… (!)

Please help me here, I’ve tried everything I can think of for hours now!

Random things I’ve tryed (not in any order, and just glimpses)

1. use the page/hi.js.rjs
2. use the render :text =\> “alert(‘Im JS’);”, :content\_type =\>  
“text/javascript”
3. respond\_to do |format|  
format.js  
end
4. headers[“Content-Type”] = "text/javascript; charset=utf-8

Thank you all in advance!  
//Nicklas RamhÃ¶j

---

<div class="post-metadata">

**Author:** ![wepic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ccd318/32.png) [@wepic](https://www.ruby-forum.com/u/wepic)\
**Post date:** [January 8, 2008, 5:52pm UTC](https://www.ruby-forum.com/t/render-update-returns-js-wrapped-in-a-html-body/125364/2 "2008-01-08T17:52:02Z")

</div>

I forgot to describing my environment:

Ruby version 1.8.6 (i686-darwin8.9.1)  
RubyGems version 1.0.1  
Rails version 2.0.2  
Active Record version 2.0.2  
Action Pack version 2.0.2  
Active Resource version 2.0.2  
Action Mailer version 2.0.2  
Active Support version 2.0.2  
Environment development  
Database adapter mysql

Mac OS X Leopard  
Firefox 2.0.0.11  
Safari 3.0.4

---

<div class="post-metadata">

**Author:** ![wepic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ccd318/32.png) [@wepic](https://www.ruby-forum.com/u/wepic)\
**Post date:** [January 8, 2008, 6:00pm UTC](https://www.ruby-forum.com/t/render-update-returns-js-wrapped-in-a-html-body/125364/3 "2008-01-08T18:00:12Z")

</div>

On 8 Jan 2008, at 16:00, Nicklas Ramhöj wrote:

> In Rails 1.2.3 it works perfectly.
> 
> BUT in Rails 2.0.2 it returns the js neatly wrapped in a full HTML-  
> body,  
> and the browser shows me nada… (!)

Is rails being dumb and adding a layout ? (in which case  
adding :layout =\> false should help)

Fred

---

<div class="post-metadata">

**Author:** ![wepic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ccd318/32.png) [@wepic](https://www.ruby-forum.com/u/wepic)\
**Post date:** [January 8, 2008, 6:07pm UTC](https://www.ruby-forum.com/t/render-update-returns-js-wrapped-in-a-html-body/125364/4 "2008-01-08T18:07:06Z")

</div>

> Is rails being dumb and adding a layout ? (in which case  
> adding :layout =\> false should help)

My guess once too, but 1. it’s not my layout that’s being rendered  
around the JS, but just a my  
code and 2 I’ve tried:

render :update, :layout =\> false, :content\_type =\> “text/javascript” do  
|page|  
page.call :alert, “Im JS”  
end

(sorry for not mentioned that above!)

Thanks for your help, please let me know if you can think of anything  
else…

//Nicklas

---

<div class="post-metadata">

**Author:** ![wepic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ccd318/32.png) [@wepic](https://www.ruby-forum.com/u/wepic)\
**Post date:** [January 9, 2008, 9:16am UTC](https://www.ruby-forum.com/t/render-update-returns-js-wrapped-in-a-html-body/125364/5 "2008-01-09T09:16:43Z")

</div>

Hi.

I found it!

Argh, why didn’t I check this earlyer:

The bad guy:

Code :

1. #application.rb
2. after\_filter :tidy
3. def tidy
4. RailsTidy.filter(response)
5. end

Thanks all for reading my post. Hope this helps any one else in the  
furure.
