bwillis / versioncake

:cake: Version Cake is an unobtrusive way to version APIs in your Rails or Rack apps
655 stars 47 forks source link

All my response body are blank string #76

Closed ArnaudRemi closed 4 years ago

ArnaudRemi commented 5 years ago

Hello.

I followed the easy readme but since i added the gem all my response body are rendered empty. I reversed my changes and it happens when i add the gem into my gemfile, with or without the initializer.

This is my versioncake.rb

VersionCake.setup do |config|

  config.resources do |r|
    # r.resource uri_regex, obsolete, deprecated, supported
    r.resource %r{.*}, [], [], [1, 2]
  end

  config.extraction_strategy = :query_parameter
  config.missing_version = 1
end

and this is my routes.rb

Rails.application.routes.draw do
  root to: "welcome#index"

  # namespace :api do
  scope module: 'api', path: '/api' do
    resources :tacos
  end
end
bwillis commented 4 years ago

Sorry for a long overdue response, but did you ever figure this out?

sethpuckett commented 4 years ago

I see the same thing. I tried with version 4.0.1 and 3.4. My app is using Rails 5.2. I tried various configurations, and even removing the versioncake config entirely. The result is the same for all routes. Response bodies are always empty.

The headers come through fine. If I set a config.response_strategy I see the expected value in the respond headers.

I tried updating jbuilder to latest. No change.

JamesCarscadden commented 4 years ago

I see this problem as well. In my case I'm using a Rails 6.0.3 "api" project, also with jbuilder.

Unfortunately I don't know enough about the Rails view rendering code to be able to debug effectively, but at some point in the pipeline it would appear that all the rendering options are lost, and so we end up with an empty body and a mime type of :text. My best guess is that this is some interaction between the ImplicitRender and Versioncake. In debugging I can see that it is finding my jbuilder templates with versions and so on, but somewhere between finding the template and actually rendering it out, the options are lost.

JamesCarscadden commented 4 years ago

Potentially some further insight here. When I remove Versioncake and trace through the rendering of the templates the code eventually arrive at '_normalize_options' method at line 99 of ActionController/metal/rendering.rb (ymmv this is for Rails 6.0.3). Ultimately without Versioncake, this calls super which brings us to '_normalize_options' of ActionView/rendering.rb where the necessary options to render the template are actually set. If I DO include Versioncake, then when _normalize_options of ActionController calls super it does not go to ActionView (I don't know why).