Skip to content

Instantly share code, notes, and snippets.

@peteryates
Last active November 7, 2019 15:35
Show Gist options
  • Save peteryates/172fafb756f3cde6e344025dc935aa95 to your computer and use it in GitHub Desktop.
Save peteryates/172fafb756f3cde6e344025dc935aa95 to your computer and use it in GitHub Desktop.
Form with acceptance validation
<%= form_with(model: account, local: true) do |form| %>
<%= form.govuk_error_summary %>
<%= form.govuk_email_field(:email) %>
<%= form.govuk_check_boxes_fieldset :terms_and_conditions,
legend: { text: 'Please accept our terms and conditions' } do %>
<%= form.hidden_field :terms_and_conditions, value: false %>
<%= form.govuk_check_box :terms_and_conditions, true, multiple: false, link_errors: true %>
<% end %>
<%= form.govuk_submit %>
<% end %>
class Account < ApplicationRecord
validates :email, presence: true
validates :terms_and_conditions, acceptance: { accept: true }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment