Trailblazer
Trailblazer
A New Architecture For Rails
About the Book
Note: This book discusses Trailblazer 1.x. We provide free guides for TRB2 on the website, but the general idea of this book still applies. A new beginner's book is on the way!
Trailblazer is a thin layer on top of Rails and brings a high-level application architecture, decent encapsulation and a new code structure. Here are the main features.
- Logicless models solely focusing on persistence.
- Skinny controllers working as endpoints, only.
- Domain objects for your business logic, known as operations.
- Form objects for deserialisation and validation.
- View models to introduce a widget architecture.
- Representers that parse and render documents for APIs.
- Twin objects for decorating models.
This book takes you for an adventure trip from Rails' code jungle to Trailblazer beach. We're building a complete Rails application using all of Trailblazer's goodies while exploiting the Rails Way where it helps us.
What we build here is not just a simple 5-minutes blog, but a full-blown commenting application with complex forms, composed views, signed-in users and admin, authentication rules, polymorphic views and operatoins, a document-based JSON API, and more. We have a strong focus on testing, object design and structuring the code using Trailblazer's concept-oriented framework.
2. The Trailblazer Architectural Style
Chapter 2 is a complete overview about all the concepts of Trailblazer, starting from domain objects, integrated form to view models, policies and twins.
3. Operations and Forms
The third chapter gives you everything you need to encapsulate your business logic into operations and building rock-solid domain components using the integrated form. We also learn how to render forms from operations, and how to test both for a good sleep.
4. Cells
We then discuss the principles of Cells view models, how to encapsulate your view into components and the way helpers work in this layer. Learning how to test your rendering and integrating those with smoke tests round up this fine chapter.
5. Nested Forms
Forms can and do represent deeply nested object structures. In this chapter we learn how to nest forms to create more than one model in an operation.
6. Composed Views and AJAX Pagination
Usability, or "UI is king!" is one of Trailblazer's maxims. We walk through advanced Cells features, learn how to embedd forms into existing pages, break Rails' "RESTfulness" and discuss AJAX-backed pagination with Cells.
7. Mastering Forms
Forms are an integral part of Trailblazer. They orchestrate deserialization of input, population and validation. The seventh chapter really dives into Reform, dynamic population, skipping nested items, form inheritance and removing items from collections. We also discuss Non-CRUD behavior and how operation and form work together to expose more than just plain CRUD semantics.
8. Callbacks
Callbacks in Trailblazer no longer sit in one huge model file but get restructured in operations. Sending email notifications, adding and inheriting callbacks, and the structure of operations are the main content of this chapter. A discussion about view caching and expiring those via callbacks will prepare you to write advanced operations.
A section about file uploads will make sure this chapter covers all major parts of post-processing business logic.
9. Authentication
Operations are the perfect place for authentication logic. We will implement sign in, sign up, mail notifications, and many more authentication-related functions in this chapter. Strong tests will make sure only authenticated users get access to certain parts of the application.
You will learn how the Tyrant gem helps implementing authentication workflows without all the pain you've had with Devise.
10. Policies and Authorization
Policies are a technique to restrict users to specific operations and UI elements. But, there's more to it. Using policies and builders, we can use polymorphism to map operations to different contexts, like anonymous users or admins. We'll refine our forms and UI for specific user types in this chapter and learn everything about policies to protect your functions from unauthorized use.
11. Hypermedia APIs: Rendering
Operations in Trailblazer integrate with representers from the Representable/Roar gem. This helps quickly setting up document APIs. This chapter discusses how representers can be inferred, specified and explicitly created to render things, comments, and their associations following the HAL media format.
12. Hypermedia APIs: Deserialization
The hardest part of API code is the deserialization: parsing documents into object graphs. Trailblazer leverages representers to parse incoming documents directly to your operation's contract, and this chapter explains all you got to know to understand every step of it.
Reader Testimonials

Pedro Visintin
This is punk! Trailblazer breaks with the established MVC dogma. This book has a bigger scope than Ruby and Rails, it's about architecture and good design. Nick made the book easy to read with some condiments of humor and lifestyle.

Jason King
The Trailblazer book smacks you in the face with a very well reasoned argument for a new architecture for Rails, Nick escorts the reader to a complete understanding of both the motivation behind Trailblazer and the effective use of it.

Yuri Freire Lima
Trailblazer helps organize my code, the book showed me how. It's very easy and intuitive, it should be shipped as an essential part of Rails.

Matthew Heath
Trailblazer has saved me from the ninth level of development hell. The book is one of the most well-written technical books I've ever had the pleasure (yes, PLEASURE) of reading. Buy it if you value your time and sanity.

Barrie Hadfield
CTO of Workshare
Trailblazer does as much for Rails as Ruby did. An amazing book and a fundamentally new way of thinking about RoR. This book is humorous, comforting and packed with insight and pragmatism. A must read for anyone committed to Rails and OO programming.

Nick Gorbikoff
Lead Developer
Haven't been this excited about Rails since 2007, Trailblazer - makes Rails development fun again. Especially on big projects. It's one of the better implementations of the ServiceObject / ViewModel / Policy layers I've seen.

Eric Skogen
Software Inventor
Trailblazer has brought the fun back to Rails for me. Nick’s years of insight in software architecture have been distilled into this helpful primer, explaining his thought process for organizing real, complex apps. Highly recommended!

Annie Caron
I searched for a long time to bring my Rails apps to the next level. TRB goes further than classic MVC and helpers - it's exactly how I imagined my structure. The book helped me a lot to understand how Trailblazer works and what the author's thinking. A must read and learn!
Table of Contents
-
-
Introduction
- How To Read This Book
- The Missing Architecture
- Learnings About Reality
-
The Trailblazer Architectural Style
- Why Trailblazer?
- A Non Intrusive Framework
- Trailblazer In A Nutshell
- Logicless Models
- Concepts and File Structure
- High-Level Domain
- Operation
- High-Level Architecture
- Validations
- Inheritance Over Configuration
- Builders
- Authorization And Policy
- Authentication
- Representers
- API: Parsing and Rendering
- Using Hypermedia
- Rendering Views
- Cells
- Twin
- Testing
- A Note On Complexity
- Summary
-
Operations And Forms
- The Example app
- The Create Operation
- Controllers
- Reform: Form Objects
- Operation’s Form Integration
- Model Semantics
- Rendering Forms
- Testing Validations
- Testing Controllers: Integration Tests
- Update Operation
- Reform and strong_parameters
-
Cells
- Rails Views and Encapsulation
- View Models
- Modelling the UI with Cells
- Anatomy of a Cell
- Rendering Collections
- Integration Tests
- Cell Tests
- Nesting Cells
- Rails and MVC
- Final Test Setup
-
The
cell
Helper - Summary
-
Nested Forms
- Adding Comments
- The Comment Concept
-
The
setup_model!
Hook - Nested Contracts
- Pre-populating Forms
- Form Processing
- Populating Forms for Validation
- Saving Nested Objects
- Flash messages and Redirecting
- Readers for Operations
- Static Form Population
- Form Presentation Helpers
- Pre-selecting Values
- Operation and Form Tests
-
Composed Views
-
The
present
Helper. - Multiple Operations for Composed Pages
- Form Submission: Widgets vs. “RESTful”
- Writing a Cells Feature
- Application-wide Features
- Simple Decorator Helpers
- Rails’ View Architecture
- Kaminari Pagination and Cells
- AJAX Pagination with Cells
- On Controller Structuring
- Cells Tests
- Smoke Tests
- Summary
-
The
-
Mastering Forms
- Things and Authors
- Adding Authors
- Dynamic Prepopulation
- Validation Population
- Skipping Blanks
- Form Debugging Techniques
- Saving
- Adding Authorships
- Non-CRUD Behavior
- Complex Validations
- Testing Create
- Presentation Tests
- Updating Things
- Hacking the View
- Helpers in Forms
- Form Inheritance
- Virtual Properties
- Populator
- Persisting the Deletion
- Testing Update
- Extracting Forms to Separate Files
-
Callbacks
- Domain Callbacks
- The Persisted Module
- Explicit Callbacks
- Imperative Callbacks
- Callbacks in Operations
- Testing Callbacks
- View Caching
- Cache Keys
- Expiring Keys
- Debugging View Caching
- Caching Composed Views
- The CacheVersion Pattern
- File Uploads
- Paperdragon
- File Validations
- Callback Groups
- Rendering Images
- Testing Uploads
- Conclusion
-
Authentication
- Populating by ID
- Tyrant
- Sign Up
- Authenticatable
- SignUp Form
- Testing SignUp
- Sign In
- Modelless Forms
- Login
- Application-wide Tyrant
- A Warm Greeting
- Signing Out
- Testing Logins
- Putting Users to Sleep
- Waking Up Sleeping Users
- Integration Tests for Wake Up
-
Authorization And Polymorphism
- Policies
- Operation Inheritance
- Polymorphic Builders
- Resolver
- Refining Operations with Modules
- Polymorphic Testing
- Polymorphic Views
- Integration Test: Create
- Updating
- Composable Operations
- Update Tests
- Delete
- Impersonate
-
Hypermedia APIs: Rendering
- File Structure
- Rendering Comments
- HAL Hypermedia Links
- Rendering
- Representer
- GET Controller
- Responders
- Inferring Representer
- Composing Representer
- Rendering Nested Documents
- Scopes and Sorting
- Index Operation
- Lonely Collections
- Filtering
-
Hypermedia APIs: Deserialization
- Deserialization in Trailblazer
- Parsing Comment
- Deserialization and Contract
- Deserialization in Reform
- Deserializing HAL
- Create
- Polymorphic Update
- Basic Auth
- Discussion: Polymorphic Operations and APIs
-
Perspectives
- This Book
- Why Not a New Framework?
- Rails
- Webmachine
- Grape
- ROM
- Roda
- Hanami
- Trailblazer
-
Introduction
- Notes
Authors have earned$10,261,184writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
500 QUIZ MMG COMMENTATI
ALS Medicina Generale500 Quiz degli ULTIMI Concorsi di Medicina Generale (2014/2016/2017/2018/2019)
Riassunti e suddivisi per area con Griglia risposte vuota e Griglia risposte esatte Ministeriale
Commentati con link alla fonte per approfondimento e ausilio allo studio
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Continuous Delivery Pipelines
Dave FarleyThis practical handbook provides a step-by-step guide for you to get the best continuous delivery pipeline for your software.
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Visualise, document and explore your software architecture
Simon BrownA short guide to visualising, documenting and exploring your software architecture.
Discrete Mathematics for Computer Science
Alexander Shen, Alexander S. Kulikov, Vladimir Podolskii, and Aleksandr GolovnevThis book supplements the DM for CS Specialization at Coursera and contains many interactive puzzles, autograded quizzes, and code snippets. They are intended to help you to discover important ideas in discrete mathematics on your own. By purchasing the book, you will get all updates of the book free of charge when they are released.
Functional Design and Architecture
Alexander GraninSoftware Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
Software Architecture and Design Practice Reference
2 Books
Dive deeper in Software Architecture with the Design Practice Reference. Learn all about software architecture and design from the books in this bundle:Software Architecture covers topics from quality attributes to designing and modeling components, interfaces, connectors, and containers, all the way to services and microservices. The Design... - #6
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #7
The Python Craftsman
3 Books
The Python Craftsman series comprises The Python Apprentice, The Python Journeyman, and The Python Master. The first book is primarily suitable for for programmers with some experience of programming in another language. If you don't have any experience with programming this book may be a bit daunting. You'll be learning not just a programming... - #8
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #10
Mastering Containers
2 Books
Docker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes!