# Render layout not working for application.xml.builder

**URL:** <https://www.ruby-forum.com/t/render-layout-not-working-for-application-xml-builder/161927>\
**Category:** Rails\
**Created:** [March 3, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/render-layout-not-working-for-application-xml-builder/161927 "2009-03-03T23:06:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zlu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@zlu](https://www.ruby-forum.com/u/zlu)\
**Post date:** [March 3, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/render-layout-not-working-for-application-xml-builder/161927/1 "2009-03-03T23:06:41Z")

</div>

I have layouts/application.xml.builder which is rendered for all xml  
reponses.  
In controllers I have:

format.xml { render :layout =\> true, :xml =\> @some\_var }

This works perfectly fine in rails 2.1.2 and stopped working after  
upgrading  
to 2.2.2.  
It appears that :layout =\> true is not taking any effect. The  
@some\_var.to\_xml is rendered just not with  
application.xl.builder any more. I googled around and tried a bunch of  
different approaches but  
stuck. Anyone seen something like this?

Thanks,

–  
Zhao

---

<div class="post-metadata">

**Author:** ![zlu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@zlu](https://www.ruby-forum.com/u/zlu)\
**Post date:** [March 4, 2009, 1:30pm UTC](https://www.ruby-forum.com/t/render-layout-not-working-for-application-xml-builder/161927/2 "2009-03-04T13:30:25Z")

</div>

Haven’t seen something like this but have you tried :layout =\>  
‘application’?

---

<div class="post-metadata">

**Author:** ![zlu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@zlu](https://www.ruby-forum.com/u/zlu)\
**Post date:** [March 17, 2009, 2:10am UTC](https://www.ruby-forum.com/t/render-layout-not-working-for-application-xml-builder/161927/3 "2009-03-17T02:10:06Z")

</div>

Heinz,

Yes I have. I wrote a tiny app to illustrate my problem.

I have one model - user.rb:  
class User \< ActiveRecord::Base  
def name  
“foo”  
end  
end

and users\_controller.rb:  
class UsersController \< ApplicationController  
def index  
respond\_to do |format|  
format.html  
format.xml do  
render :xml =\> User.new, :layout =\> ‘application’  
end  
end  
end  
end

I defined routes for it: map.resources :users

Then I change this to vary rails’ versions for testing:  
RAILS\_GEM\_VERSION = ‘2.2.2’ unless defined? RAILS\_GEM\_VERSION

Using :layout =\> ‘application’ or not doesn’t matter. When I hit  
[http://localhost:3000/users.xml](http://localhost:3000/users.xml)  
I get this output:

Processing UsersController#index to xml (for 127.0.0.1 at 2009-03-16  
17:41:10) [GET]  
[4;36;1mSQL (0.3ms) [0;1mSET SQL\_AUTO\_IS\_NULL=0  
[4;35;1mUser Columns (1.5ms) SHOW FIELDS FROM `users`  
Rendering template within layouts/application  
Completed in 34ms (View: 6, DB: 2) | 200 OK [[http://localhost/](http://localhost/)  
users.xml]

As you can see, it is renderin layouts/application.

I have defined views/layouts/application.xml.builder as such:  
xml.instruct!

xml.response do  
xml \<\< yield  
end

## And what I get is:

What I expect to get is xml instruct on top,  
then a response node, with user inside.

Any more insight will be greatly appreciated.

Zhao

On Mar 4, 5:30 am, Heinz S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
