43

In rails 4.2 respond_with has been moved out of core into the responders gem.

Beta release notes.

respond_with has moved out and into its own proper home with the responders gem.

Can someone please explain why? What makes the responders gem its proper home? What is wrong with it staying in the Rails gem?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Ryan-Neal Mes
  • 6,003
  • 7
  • 52
  • 77
  • Why wouldn't something responsible for defining the response belong with all the other responder stuff? – Dave Newton Sep 23 '14 at 15:14
  • 6
    Cool ... just trying to learn here. I would have thought people using the Rails gem wouldn't want to have to include the responders gem every time in their gemfile since they are most likely going to use it in every application Rails uses. – Ryan-Neal Mes Sep 23 '14 at 15:25
  • Actually I think most people don't use this functionality. It was build with an idea in mind that you can create both an app (with UI) and JSON API at the same time. Practically I've never done that and I worked on quite a few Rails projects. – Mike Szyndel Sep 23 '14 at 15:49
  • 18
    Disagree that this is opinion-based. The decision maker gave his reasons, which I've quoted in my answer. Yes his decision was based on his opinions, as are all decisions ever, but the answer to the OP's question is factual. Whether one agrees with this decision is of course an opinion, but that is not what the OP asked. – Whit Kemmey Sep 24 '14 at 17:58
  • 1
    @MichalSzyndel I actually use `respond_with` a lot as a substitute for inherited_resources/make_resourceful. Anyway, for most apps, it should be possible to create a RESTful app and a JSON API at the same time. – Marnen Laibow-Koser Jan 26 '15 at 21:07
  • 4
    It is very common for an action to return an HTML (as first reponse) and json in the next one (think paging) this can be very nicely done with respond_to , I think it's a wrong call to move it outside and discourage it as a result. – JAR.JAR.beans Aug 18 '15 at 15:26

1 Answers1

61

Rationale from David Heinemeier Hansson (creator of Ruby on Rails):

I'd like to take this opportunity to split respond_with/class-level respond_to into an external plugin. I'm generally not a fan of the code that comes out of using this pattern. It encourages model#to_json and it hides the difference between HTML and API responses in ways that convolute the code.

So how about we split this into a gem for 4.2, with the current behavior, but also with an option to get the new behavior as suggested here through a configuration point.

Full discussion at this link:

https://github.com/rails/rails/pull/12136#issuecomment-50216483

Whit Kemmey
  • 2,230
  • 22
  • 18