I am having trouble getting my Hobo controllers to respond to requests in 
json format.

In a non-Hobo rails application, I am accustomed to enabling json responses 
with this simple
statement at the top of a controller class definition:

class WidgetsController < ApplicationController
  respond_to :html, :json
...

Then, I can retrieve any valid route with '.json' appended to the URL to 
see my data in JSON format rather than HTML. e.g.:

http://localhost:3000/widgets.json
http://localhost:3000/widgets/3.json

When I do that with a Hobo application, my output is still in HTML 
(although the header tells the browser
that the content type is JSON so the browser doesn't process the HTML, it 
just shows me the source).

One workaround I've found is to define response methods like this:

class WidgetsController < ApplicationController
...
        def show_response
            respond_to do |format|
              format.html do
                super
              end
              format.json do
                render json: self.this
              end
         end

(I figured this out from revere-engineering the hobo source code)

Until I find a better solution, I am deploying a workaround module that 
I've written
to wrap all of the show_* methods via class_eval meta programming.
I just include it in any controller which I want to respond to JSON.  i.e.:


class WidgetsController < ApplicationController
  respond_to :html, :json
  include HoboWorkarounds::RespondToJson
...

It's kinda kludgey but it gets the job done.

Anybody got any suggestions for a more kosher solution?

Thanks.

- Steve Madere

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to