When rendering a xml page, rhtml layouts should not be used. For example, starting with a new rails project:
file: app/controllers/test_controller.rb
= class TestController < ApplicationController
def my_action
respond_to do |format|
format.html
format.xml
end
end
end
file: app/views/layout/test.rhtml
<body>
<%= yield %>
</body>
file: app/views/test/my_action.rxml
xml.instruct!
xml.my_node(:name => 'bubba')
Now if I start script/server up on port 4000 and I run:
curl -H "Accept: application/xml" http://localhost/test/my_action I should get:
<?xml version="1.0" encoding="UTF-8"?>
<my_node name="bubba"/>
but it gives me (because the layout is applied)
<body>
<?xml version="1.0" encoding="UTF-8"?>
<my_node name="bubba"/>
</body>