Versioned legal document management for Rails. Track and enforce user acceptance of Terms of Service, Privacy Policy, and other legal agreements with versioned documents and audit trails.
Add to your Gemfile:
gem "agreement_engine"Then run:
bundle install
rails agreement_engine:install:migrations
rails db:migrateCreate config/initializers/agreement_engine.rb:
AgreementEngine.configure do |config|
config.agreements = [
AgreementEngine::Agreement.new(
id: :terms_of_service,
title: "Terms Of Service",
version_column: :accepted_terms_of_service_version_id,
document_type: :terms_of_service,
prompt_when_updated: true
),
AgreementEngine::Agreement.new(
id: :privacy_policy,
title: "Privacy Policy",
version_column: :accepted_privacy_policy_version_id,
document_type: :privacy_policy,
prompt_when_updated: true
)
]
end# app/models/user.rb
class User < ApplicationRecord
include AgreementEngine::Signable
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include AgreementEngine::Enforceable
end# config/routes.rb
mount AgreementEngine::Engine, at: "/"rails agreement_engine:seedAgreementEngine defaults to Devise conventions. Override for other auth systems:
AgreementEngine.configure do |config|
config.current_user_method = ->(c) { c.current_user }
config.signed_in_method = ->(c) { c.user_signed_in? }
config.auth_controller_method = ->(c) { c.devise_controller? }
config.sign_out_method = ->(c) { c.sign_out(c.current_user) }
endThe engine provides:
GET /agreements/:id- Show agreement for acceptancePATCH /agreements/:id- Accept agreementDELETE /agreements/:id- Decline agreement (signs user out)GET /terms- Public terms of service pageGET /privacy- Public privacy policy pageGET /admin/documents- Admin CRUD for managing document versions
bundle install
bundle exec rake test