A Deep Dive
Have you wanted to get a better grasp of the Rails code? In particular, do you want to create your own Rails renderer or resolver? What the heck is the difference between a template handler and a custom renderer anyway?
If you answer yes to any of those questions, check out my new Rails Rendering course on Pluralsight. It teaches you how to create a template handler, a custom renderer, and a file resolver for Rails, taking a deep dive into the Rails rendering stack along the way.
Free 30 Day Access!
Don't have a Pluralsight membership? No problem: I have a bushel of 30 day passes to give away! Send me a tweet or an email (noel at peden dot biz) and I'll get you a code.
What Is A Template Handler?
A template handler knows how to read a specific template type (identified by its extension, such as html.erb) and returns its contents as ruby code.
What Is A Custom Renderer?
A custom renderer provides much more flexibility, and may or may not use templates. To use a custom renderer you pass an identifying key to the render method. For example,
render json: @foo uses a custom renderer to produce json output. With a custom renderer, you have complete control over the response, letting you set headers, change the content, render a template or not, etc.
What Is A File Resolver?
A file resolver takes a given set of request parameters and returns an array of matching templates. The parameters are the template name, extension, variant, locale, and available renderers. Rails comes with a file resolver which uses these parameters to search the file system for templates. You can, however, create a file resolver which retrieves templates from anywhere. For instance, in Crafting Rails Applications José Valim shows how to serve templates from a database. Or, consider my S3-Rails gem which retrieves templates from Amazon's S3 service.