Setting up Trailblazer in projects is usually not more than installing a few gems.
This guide will walk you through the configuration of all major frameworks such as Rails, Sinatra, Hanami and Roda.
As Trailblazer is highly modular, you have to make sure you include the correct gems in your
Gemfile example for a Rails application.
gem "trailblazer" gem "trailblazer-rails" # optional, in case you want Cells. gem "trailblazer-cells" gem "cells-erb" # Or cells-haml, cells-slim, cells-hamlit. gem "cells-rails"
This will also load
reform-rails making the integration very smooth.
Here’s a sample
Gemfile for a non-Rails project that doesn’t use
gem "trailblazer" gem "trailblazer-loader" # optional, if you want us to load your concepts. gem "reform", ">= 2.2.0" gem "dry-validation", ">= 0.8.0" # optional, in case you want Cells. gem "trailblazer-cells" gem "cells-erb" # Or cells-haml, cells-slim, cells-hamlit.
Note that you need to invoke the loader manually. Usually, this would happen in an initializer.
Trailblazer::Loader.new.(concepts_root: "./concepts/") do |file| require_relative(file) end
You can configure what validation engine you want to use.
In Rails, use an initializer, e.g.
config/initializer/trailblazer.rb for that.
Rails.application.config.reform.validations = :dry
ActiveModel::Validations will be configured, per default.
To set the default validation engine, it’s easiest to monkey-patch Reform itself.
Simply for a matter of readability, this should be done before you start defining forms.
Note that you can still use alternative validations per form class.
- Slim recommended (works with all gems such as Formular)