ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
209 stars 51 forks source link

Problem with request.format #34

Closed abrisse closed 11 years ago

abrisse commented 11 years ago

request.format isn't always set with rabl-rails. I had no problem with rabl.

The response header 'Content-Type' is sometimes invalid too. (return text/html instead of application/json during the first request in my app).

Any idea ?

abrisse commented 11 years ago

If I change the following lines :

format.upcase!
Renderers.const_get(format).new(context, locals).render(compiled_template)

to

Renderers.const_get(format.upcase).new(context, locals).render(compiled_template)

It seems to fix the problem that occurs with a Accept: application/json. At the next request, params[:format] equals :JSON instead of :json which causes a 406 Error HTTP (since I use a respond_to :json in my controller)

ccocchi commented 11 years ago

What is the value of your context.params[:format] ? because your change is supposed to do absolutely nothing different..

Can you reproduce this into a small app or within a test ?