Chapter 1Creating Our Own Renderer

  • Rails plug-ins and their basic structure

  • How to customize the render method to accept custom options

  • Rails rendering-stack basics

Like many web frameworks, Rails uses the model-view-controller (MVC) architecture pattern to organize our code. The controller usually is responsible for gathering information from our models and sending the data to the view for rendering. On other occasions, the model is responsible for representing itself, and then the view does not take part in the request; this most often happens in JavaScript Object Notation (JSON) requests. The following index action illustrates these two scenarios:

​ 
​class​ PostsController < ApplicationController
​ 
​def​ index
​ 
​if​ ...

Get Crafting Rails 4 Applications, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.