1

So I've got a Padrino app with a controller that looks roughly like this (simplified for brevity):

App.controllers :questions do
  get :index, :with => :id, :provides => [:html, :json] do
    # Stuff
  end

  post :index, :with => :id, :provides => [:html, :json] do
    # Other stuff
  end
end

If I hit "questions/1" in my browser, I see the HTML page for the given question. If I hit "questions/1.json", I see the JSON representation of the question. Exactly like I'd expect.

Now, if I submit a POST request to "questions/1" via a web form, it works. But if I try to send a POST request to "questions/1.json" (signaling that I want the response in JSON format—or at least that's how I thought it worked), I get a 405 Method Not Allowed.

I'm guessing there's something basic I'm misunderstanding here. What am I missing? More importantly, how should I define a route to accept POST requests and provide either HTML or JSON responses?

Dan Tao
  • 125,917
  • 54
  • 300
  • 447

1 Answers1

1

Well, I'm not really sure why this was happening; but for now I've gotten around the issue by setting the "ACCEPT" header in my POST request to "application/json" instead of tacking ".json" onto the end of the URL (and upon my limited internet research, this may be the preferred approach anyway).

Dan Tao
  • 125,917
  • 54
  • 300
  • 447