Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Blueprinter DSL

Define your base class

Define an ApplicationBlueprint for your blueprints to inherit from. Any global configuration goes here: common fields, views, partials, formatters, extensions, and options.

class ApplicationBlueprint < Blueprinter::Blueprint
  extensions << MyExtension.new
  options[:exclude_if_nil] = true
  field :id
end

Define blueprints for your models

This blueprint inherits everything from ApplicationBlueprint, then adds a name field and two associations that will render using other blueprints.

class WidgetBlueprint < ApplicationBlueprint
  field :name
  object :category, CategoryBlueprint
  collection :parts, PartBlueprint
end

There's a lot more you can do with the Blueprinter DSL. Fields are a good place to start!