# Stop rendering a response in the default layout

**URL:** <https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134>\
**Category:** Rails\
**Created:** [March 17, 2009, 4:10pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134 "2009-03-17T16:10:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [March 17, 2009, 4:10pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134/1 "2009-03-17T16:10:50Z")

</div>

I am trying to follow this tutorial here by Ryan :

> **[\#136 jQuery - RailsCasts](http://railscasts.com/episodes/136-jquery)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

it is a AJAX tutorial on using jquery and expecting the response to be  
in the form of javascript that will be acted upon by the browser.  
however, i am getting the response to be rendered in the default  
layout. i am getting the appropriate response but the js is embedded  
in HTML and thus not execuuted. is there a way to turn the rendering  
off for certaini cases?

thanks,  
tashfeen

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [March 17, 2009, 4:22pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134/2 "2009-03-17T16:22:02Z")

</div>

On 17 Mar., 16:10, “tashfeen.ekram” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am trying to follow this tutorial here by Ryan :[#136 jQuery - RailsCasts](http://railscasts.com/episodes/136-jquery)
> 
> it is a AJAX tutorial on using jquery and expecting the response to be  
> in the form of javascript that will be acted upon by the browser.  
> however, i am getting the response to be rendered in the default  
> layout. i am getting the appropriate response but the js is embedded  
> in HTML and thus not execuuted. is there a way to turn the rendering  
> off for certaini cases?

Rails should really not use the layout unless it’s an HTML request.  
Let me ask you something: Did you accidentally call the view  
create.html.erb instead of create.js.erb? Remember, the name of a view  
is separated in three parts by dots: The first one is the name of your  
action (in this case “create”), the second one is the format (in this  
case it should be “js” to avoid embedding the output in the layout),  
the third is the template language (in this case “erb” or embedded  
Ruby, but it could also be “haml”, “builder”, “rjs” or whatever suits  
the need of that specific view).

And then if you are sure that the view is correctly named: What  
version of Rails do you use? You can find out by looking in your  
environment.rb file.

–  
Cheers,  
David K.  
[http://twitter.com/rubyguy](http://twitter.com/rubyguy)

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [March 17, 2009, 6:53pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134/3 "2009-03-17T18:53:09Z")

</div>

here is the js that i am using for the request. does it not make a js  
request?  
[http://pastie.org/418937](http://pastie.org/418937)

here is my controller:

[http://pastie.org/418941](http://pastie.org/418941)

then i am using create.js.erb for the response…

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [March 17, 2009, 7:37pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134/4 "2009-03-17T19:37:56Z")

</div>

i am using rails 2.3.0.

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [March 17, 2009, 7:40pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134/5 "2009-03-17T19:40:18Z")

</div>

here is specifically what i get in my firefox debug window:

syntax error

\<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [March 20, 2009, 9:29pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134/6 "2009-03-20T21:29:21Z")

</div>

On 17 Mar., 19:39, “tashfeen.ekram” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > request?[http://pastie.org/418937](http://pastie.org/418937)
> 
> > here is my controller:
> 
> > [http://pastie.org/418941](http://pastie.org/418941)
> 
> > then i am using create.js.erb for the response…

Well, if you are sure that:

1. You have correctly named the view “create.js.erb”
2. You don’t have a layout called something like “application.js.erb”

… I have really have no clue what’s going on here. I suggest you try  
to upgrade the application to the latest version of Rails, and if that  
doesn’t fix it, I’ld be more than happy if you zipped the app and  
uploaded it somewhere, so I could take a closer look.

–  
Cheers,  
David K.  
[http://twitter.com/rubyguy](http://twitter.com/rubyguy)

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [March 21, 2009, 7:58pm UTC](https://www.ruby-forum.com/t/stop-rendering-a-response-in-the-default-layout/163134/7 "2009-03-21T19:58:28Z")

</div>

That’s your problem right there - 2.3.0 (the first RC) had issues with  
template handling on javascript requests. See these tickets:

[http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2052](http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2052)  
[http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1844](http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1844)

Upgrading to 2.3.2 will fix this.

–Matt J.
