Forum: Ruby on Rails Stop rendering a response in the default layout

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
tashfeen.ekram (Guest)
on 2009-03-17 17:10
(Received via mailing list)
I am trying to follow this tutorial here by Ryan :
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?

thanks,
tashfeen
(Guest)
on 2009-03-17 17:22
(Received via mailing list)
On 17 Mar., 16:10, "tashfeen.ekram" <removed_email_address@domain.invalid> 
wrote:
> I am trying to follow this tutorial here by Ryan 
: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
tashfeen.ekram (Guest)
on 2009-03-17 19:53
(Received via mailing list)
here is the js that i am using for the request. does it not make a js
request?
http://pastie.org/418937

here is my controller:

http://pastie.org/418941

then i am using create.js.erb for the response...
tashfeen.ekram (Guest)
on 2009-03-17 20:37
(Received via mailing list)
i am using rails 2.3.0.
tashfeen.ekram (Guest)
on 2009-03-17 20:40
(Received via mailing list)
here is specifically what i get in my firefox debug window:

syntax error
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n
(Guest)
on 2009-03-20 22:29
(Received via mailing list)
On 17 Mar., 19:39, "tashfeen.ekram" <removed_email_address@domain.invalid> 
wrote:
> > request?http://pastie.org/418937
>
> > here is my controller:
>
> >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
Matt J. (Guest)
on 2009-03-21 20:58
(Received via mailing list)
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-...
http://rails.lighthouseapp.com/projects/8994-ruby-...

Upgrading to 2.3.2 will fix this.

--Matt J.
This topic is locked and can not be replied to.