Rendering as XML doesn't work


#1

Hey,

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>"
  end
end

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!


#2

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'
      end
    end
  end
end

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.


#3

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.


#4

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


#5

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


#6

@philnash Thanks for opening up the clear issue https://github.com/tongueroo/jets/issues/172

Fixed in https://github.com/tongueroo/jets/pull/173 Released in v1.6.5


#7

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