-
-
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
cellHelper - 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
presentHelper. - 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
Trailblazer
A New Architecture For Rails
Trailblazer introduces several new abstraction layers into Rails. It gives developers structure and architectural guidance and finally answers the question of "Where do I put this kind of code?" in Rails. This book walks you through a realistic development of a Rails application with Trailblazer and discusses every bloody aspect of it.
The author is letting you choose the price you pay for this book!
Trailblazer introduces several new abstraction layers into Rails. It gives developers structure and architectural guidance and finally answers the question of "Where do I put this kind of code?" in Rails. This book walks you through a realistic development of a Rails application with Trailblazer and discusses every bloody aspect of it.
About
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.
Price
Pick Your Price...
Minimum price
Free!
$9.99
You pay
$9.99Author earns
$7.99Author
About the Author
Nick Sutterer
Nick loves working on open-source frameworks, and that's what he does almost every day. He also loves people, surfing, beer, skateboarding and loud music. Make sure to hug him should you ever meet him in person.

Episode 32
An Interview with Nick Sutterer
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
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) and EPUB (for phones, tablets and 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
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.