Content negotiation not working with respond_to stanza

MrKickkiller

Good afternoon Stack Overflow,

def show
   # Translating ID to event
   @event = Event.find(params[:id])
   respond_to do |format|
     format.html
     format.json { render :json => @event }
   end
end

This code should (according to what I read online) generate an html response when the Accept header is set to text/html, and JSON whenever the header is set to application/json. Yet whenever I test this with Postman I always end up getting the representation of the resource that is set first.

In the above code that would be html, even when the accept header is set solely to Json. If I switch them around, I get a json representation, indifferent of what I set the header.

Side question: I'm kinda new to Ruby, and would like to fully understand what the do |x| do_a() do_b() syntax/stanza is. Is this like a Switch statement or more a lambda?

MrKickkiller

Solution found

My brain just gave out for 2 days, because apparently I was sending Content-Type headers in a GET request, instead of the appropriate Accept Header.

Thx @yoones for trying to help me :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Respond_to block is not working

From Dev

Respond_to block is not working

From Dev

Rails respond_to redirect not working

From Dev

Content negotiation to return HTML

From Dev

PhalconPHP: content negotiation?

From Dev

Restlet Content Type Negotiation

From Dev

Content negotiation using WebSharper

From Dev

PhalconPHP: content negotiation?

From Dev

respond_to block not working in mobile version of rails application

From Dev

Spring boot controller content negotiation

From Dev

Jersey - content negotiation for error handling

From Dev

Spring MVC Content Negotiation throwing ClassCastException

From Dev

SupportedMediaTypes not used when doing content negotiation

From Dev

Why not use content negotiation to return JSON object?

From Dev

How to Use Content Negotiation in Spring Data Rest?

From Dev

How to disable content negotiation for Spring Actuators?

From Dev

Content Negotiation when looking at different output formats

From Dev

Content negotiation for File Download In Web API

From Dev

Is there a simple way to solve content negotiation in Spring boot

From Dev

How to Use Content Negotiation in Spring Data Rest?

From Dev

What is performing Transparent Content Negotiation in Apache

From Dev

If respond_to? not returning anything

From Dev

Does HTTP content negotiation respect media type parameters

From Dev

spring cloud config-server .properties content-negotiation failing

From Dev

Is there better approach to Accept Header based content negotiation in Spring API?

From Dev

Why would HTTP content negotiation be preferred to explicit parameters in an API scenario?

From Dev

Is HTTP content negotiation being used by browsers and servers in practice?

From Dev

How to add csv MimeType to spring content-negotiation?

From Dev

Rails: respond_to JSON and HTML

Related Related

  1. 1

    Respond_to block is not working

  2. 2

    Respond_to block is not working

  3. 3

    Rails respond_to redirect not working

  4. 4

    Content negotiation to return HTML

  5. 5

    PhalconPHP: content negotiation?

  6. 6

    Restlet Content Type Negotiation

  7. 7

    Content negotiation using WebSharper

  8. 8

    PhalconPHP: content negotiation?

  9. 9

    respond_to block not working in mobile version of rails application

  10. 10

    Spring boot controller content negotiation

  11. 11

    Jersey - content negotiation for error handling

  12. 12

    Spring MVC Content Negotiation throwing ClassCastException

  13. 13

    SupportedMediaTypes not used when doing content negotiation

  14. 14

    Why not use content negotiation to return JSON object?

  15. 15

    How to Use Content Negotiation in Spring Data Rest?

  16. 16

    How to disable content negotiation for Spring Actuators?

  17. 17

    Content Negotiation when looking at different output formats

  18. 18

    Content negotiation for File Download In Web API

  19. 19

    Is there a simple way to solve content negotiation in Spring boot

  20. 20

    How to Use Content Negotiation in Spring Data Rest?

  21. 21

    What is performing Transparent Content Negotiation in Apache

  22. 22

    If respond_to? not returning anything

  23. 23

    Does HTTP content negotiation respect media type parameters

  24. 24

    spring cloud config-server .properties content-negotiation failing

  25. 25

    Is there better approach to Accept Header based content negotiation in Spring API?

  26. 26

    Why would HTTP content negotiation be preferred to explicit parameters in an API scenario?

  27. 27

    Is HTTP content negotiation being used by browsers and servers in practice?

  28. 28

    How to add csv MimeType to spring content-negotiation?

  29. 29

    Rails: respond_to JSON and HTML

HotTag

Archive