News for hackers. Stuff that matters.
Re:Why critics of Rails have it all wrong (and Ruby's bright... by mtkd on Thursday September 13, 2012 @11:36AM (#4516688)
"Rails is great for JSON APIs"

Rails is good for simple APIs (especially adding an API to an existing HTML site).

However, if you want to do more than that, elegantly - it isn't great yet. You quickly end up with some fairly messy serialization hacks and confusion between what should sit in the controller and the model.

The active_model_serializers gem is a really good start, but there is a way to go to get to the level of convention the rest of Rails provides.

Soon it will be great I have no doubt and the convention/stability of Rails will lead a lot of businesses to start using it.

Re:Why critics of Rails have it all wrong (and Ruby's bright... by nateberkopec on Thursday September 13, 2012 @11:53AM (#4516822)
Why not use a format-specific DSL, like DHH does with jbuilder?

That's not messy at all, it's basically just another TemplateHandler.

Re:Why critics of Rails have it all wrong (and Ruby's bright... by codenerdz on Thursday September 13, 2012 @12:30PM (#4517060)
Or RABL if you want both XML and JSON output
Re:Why critics of Rails have it all wrong (and Ruby's bright... by joedoe55555 on Thursday September 13, 2012 @02:23PM (#4517747)
Or XSLT if you want both Oracle and IIS at the same time
Re:Why critics of Rails have it all wrong (and Ruby's bright... by nateberkopec on Thursday September 13, 2012 @06:38PM (#4519023)
That sounds horrible.
Re:Why critics of Rails have it all wrong (and Ruby's bright... by randomdata on Thursday September 13, 2012 @01:34PM (#4517483)
I do agree that the way to provide APIs has been poorly conveyed by the core members. All of the samples end up amounting to:

  render :xml => @objects
Which, naturally, falls apart quickly beyond the most basic serialization. However, as long as you treat the API like any other view (even HTML is just another API format), then Rails does a pretty decent job.
Re:Why critics of Rails have it all wrong (and Ruby's bright... by cheald on Thursday September 13, 2012 @12:27PM (#4517041)
Use decorators. Draper is my personal favorite, and it very cleanly solves the issue of serialization nightmares and controller/model confusion.

(I hope that it ends up in the Rails core someday, because it really is a gamechanger in how Rails is used for non-HTML content!)

Re:Why critics of Rails have it all wrong (and Ruby's bright... by VeejayRampay on Saturday September 15, 2012 @12:17AM (#4525277)
Agreed, Draper + Jbuilder and you got yourself plenty of decoupling and beauty.