RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Presenters As A Solution To as_json Woes In Rails APIs

A quick brain dump on how the presenter pattern might be an acceptable solution to the pitfalls of using as_json in versioned Rails APIs.

Comments

I like your approach here, since these versioned APIs are representations of a model, they do not belong in the controller or the model. IMO, these are simple representations that belong in a presenter (as shown here) or in the view. I took a different approach and built a gem to make this easier: https://github.com/nesquena/rabl . With that gem you can simply declare your versioned apis in templates where they belong and it also supports inheritance and partials to keep them DRY.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in