Rendering as XML doesn't work


I’m new to Jets and excited about its potential. Just started with it today and the first thing I tried to do was to render some XML (I work at Twilio and I’m just building a simple message responder to try this out, so need to return TwiML.)

I built a really simple controller, but when I render as xml the response header comes back with a content type of text/html instead of text/xml or application/xml. A minimal example of this is:

class MessagesController > ApplicationController
  def create
    render xml: "<Hello>World</Hello>"

I can get the right response header if I include a content_type attribute, but I would expect render xml: content to set the right header.

Am I doing something wrong or is this a bug? Thanks!

Nope, don’t see anything wrong with your code. Looks like xml rendering is not supported yet. Bummer.

Underneath the hood, Jets uses actionpack and actionview to handle rendering currently. So it should be pretty straightforward to add. @genail started some work in this area and was able to get jbuilder working. Here’s his snippet of code that added jbuilder support:

require 'jbuilder/jbuilder_template'

class Jbuilder
  class Turbine < ::Jets::Turbine
    initializer :jbuilder do
      ActiveSupport.on_load :action_view do
        ActionView::Template.register_template_handler :jbuilder, ::JbuilderHandler
        require 'jbuilder/dependency_tracker'

It makes use of a Jets Turbine. So guessing that an xml builder might need to be registered.

Think it’ll be great of this just worked out of the box. Will dig into this, unsure when. Happy to also consider pull requests.

Thanks for taking a look. I did try to trace back what was happening until I got to calling ActionController::Base methods.

I found this part that looks for xml among the incoming options and sets it in the render_options object. I assume this at least gets the content that I try to render as xml into the renderer itself, but it doesn’t explain why it doesn’t have the right content type set.

I’d love to try to help fix this, any pointers about how this hangs together would be welcome.

Also, should I raise this as an issue on the GH repo?

@philnash Yup! Makes sense as an issue, haven’t had a chance to create one yet. Feel free to do so :+1:

@philnash Thanks for opening up the clear issue

Fixed in Released in v1.6.5

Awesome, thanks for the quick response. And it was easier than I thought it was too :smiley: