-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Layered Design for Ruby on Rails Applications
By :

Ruby on Rails is popular for both HTML-first and API-first applications. So far in this chapter, we’ve only considered HTML-driven applications, with templates, view helpers, and so on—all the frontend things. What about pure backend Rails applications? Is there a representation layer? Sure, there is.
Although API-only Rails applications delegate most of the browser-related work to frontend frameworks, it’s still the responsibility of the application’s presentation layer to prepare responses to HTTP requests.
In most cases, we deal with JSON responses. So, let’s discuss how we can turn our application’s data into JSON strings and how the presenter pattern could be used here, too.
In Rails, there are a couple of built-in options for generating JSON responses. Let’s first discuss them.
Rails makes it dead simple to respond with JSON from controllers...