Skip to main content

This is a guide on using the GOV.UK Design System Form Builder

  1. Index
  2. Getting started

Getting started

Installation

The form builder is suitable for use with any Rails application that uses the GOV.UK Design System. If you’re starting from scratch, the easiest way to hit the ground running is to use the DfE Rails Boilerplate.

Once your application is working, simply add the following line to your Gemfile and run bundle install.

gem 'govuk_design_system_formbuilder'

Now we just need to tell Rails which form builder to use. We can do this globally by amending the ApplicationController.

class ApplicationController < ActionController::Base
  default_form_builder GOVUKDesignSystemFormBuilder::FormBuilder
end

Alternatively, if you’re not quite ready to make the full switch, you can specify the form builder on a form-by-form basis. All examples in this guide are written using Slim but the form builder works just as well with ERB or Haml.

= form_for @some_object, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f|
  = f.govuk_text_field :name
  = f.govuk_phone_field :telephone_number

If you made it this far and everything’s working, well done!