Add e-signatures and clickwrap to Rails
To add e-signatures and clickwrap to Rails, call the REST API from a controller with Net::HTTP: there is no gem, because the server SDK exists for Node.js only. One action creates the session with the secret key and keeps the pinned versions in the Rails session, and another confirms the record. Esign Comply seals each acceptance as an independent record.
Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.
No gem to install: Net::HTTP is enough
Rails quickstartFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
# Step 4: create the session with the secret key. The browser gets the client token only. def ceremony origin = request.headers["Origin"] || request.base_url status, created = EsignComply.call(:post, "/sessions", idempotency_key: "signup-#{SIGNER[:external_id]}-#{SecureRandom.uuid}", body: { profile: ENV.fetch("ESIGNCOMPLY_PROFILE_ID"), signer: SIGNER, documents: [ { document: DOCUMENTS["terms"], version: "current" }, { document: DOCUMENTS["privacy"], version: "current" } ], context: { url: "#{origin}/signup", locale: "en-US", purpose: "account_signup" } }) return render(json: { error: created.dig("error", "code") }, status: :bad_gateway) unless status == 201 # The Rails session is an encrypted, signed cookie: the browser carries it and cannot read or change it. session[:pinned_versions] = created["documents"].map { |d| d["version_id"] }.sort render json: { clientToken: created["client_token"], apiUrl: created["api_url"], documents: created["documents"] } end
# app/services/esign_comply.rb require "net/http" # There is no gem: these are plain HTTPS calls with the secret key. module EsignComply API = ENV.fetch("ESIGNCOMPLY_API_URL", "https://esigncomply.com/v1") # One call to the Esign Comply API. Returns [status, parsed JSON]. def self.call(method, path, body: nil, idempotency_key: nil) uri = URI("#{API}#{path}") request = (method == :post ? Net::HTTP::Post : Net::HTTP::Get).new(uri) request["Authorization"] = "Bearer #{ENV.fetch('ESIGNCOMPLY_API_KEY')}" request["Idempotency-Key"] = idempotency_key if idempotency_key if body request["Content-Type"] = "application/json" request.body = body.to_json end response = nil 3.times do |attempt| response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: 5, read_timeout: 10) do |http| http.request(request) end # Over the rate limit: wait for Retry-After (1 to 5 seconds) and try again, twice at most. Nothing else is retried. break unless response.code == "429" && attempt < 2 sleep response["Retry-After"].to_f.clamp(1, 5) end [response.code.to_i, JSON.parse(response.body)] end end
# Step 6: confirm the record with the secret key before the account exists. def confirm # An empty body carries no record ID. Refuse it here: an empty ID, or one of dots only, would ask the API for another path. record_id = params[:recordId].to_s return render(json: { confirmed: false }, status: :conflict) if record_id.delete(".").empty? status, record = EsignComply.call(:get, "/records/#{ERB::Util.url_encode(record_id)}") confirmed = status == 200 && SEALED.include?(record["status"]) && record["livemode"] == LIVE && record.dig("signer", "external_id") == SIGNER[:external_id] && record["documents"].map { |d| d["version_id"] }.sort == session[:pinned_versions] logger.info(confirmed ? "confirmed #{record['id']} (#{record['status']})" : "refused") return render(json: { confirmed: false }, status: :conflict) unless confirmed # Only now create the account, and store record["id"] and record["receipt"] with it. render json: { confirmed: true, recordId: record["id"] } end
How do you integrate Esign Comply with Rails?
In Rails the integration is one controller and one service method. session is an encrypted cookie, so the versions the server pinned travel with the visitor and a first run needs no table. The page sends the token from csrf_meta_tags with each POST, and the document action marks the registered HTML html_safe.
Rails describes itself as a full-stack framework.
Source: rubyonrails.org, read on .- Session actionapp/controllers/signup_controller.rb
- The API callapp/services/esign_comply.rb
- Confirm actionapp/controllers/signup_controller.rb
Run on 2026-11-26 with Rails 8.1.4.1 and Puma 8.1.2 on Ruby 3.4.13 (the official Ruby container image), with the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode.
What prompt adds Esign Comply clickwrap to a Rails app?
Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes in Rails, what to build and what never to do, and it ends with the rules block for your project.
The rules block lives at /rules.md. Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The prompt generator writes the long version, with your own document and profile IDs.
Pages for each AI toolAdd Esign Comply clickwrap to my Rails app: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.
Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/rails.md (the steps and the tested code for Rails)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)
Rails facts
- There is no Esign Comply gem. Do not install or invent one. A small service calls the REST API at https://esigncomply.com/v1 with Net::HTTP, Authorization: Bearer and the secret key.
- The browser SDK is a script tag: https://esigncomply.com/sdk/v1/esigncomply.js. It defines the global EsignComply.
- The secret key is in the environment variable ESIGNCOMPLY_API_KEY. Rails does not read .env files on its own. Never print the key.
- Every POST from the page carries the token from csrf_meta_tags in the X-CSRF-Token header, or Rails answers 422.
- Keep the pinned version IDs in session. The Rails session cookie is encrypted, so the browser cannot read or change it.
- Render the registered document HTML with html_safe. Without it Rails escapes the tags and the page no longer matches the registered version.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.
Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Action for POST /api/ceremony: call POST /v1/sessions with an Idempotency-Key, save the pinned version IDs in session, and return only clientToken, apiUrl and documents.
4. Action for GET /legal/:slug: render the html from GET /v1/documents/{id}/versions/{version_id}/content inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Action for POST /api/signup/confirm: call GET /v1/records/{id} and require: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the server-owned state. Only then create the account.
Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.
Check before you report success
- Run: npx esigncomply check --url http://localhost:3000/signup --callback http://localhost:3000/api/signup/confirm
Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.
Then add the rules block to this project's instruction file: https://esigncomply.com/rules.mdWhat goes wrong when you add e-signatures in Rails?
These are specific to Rails. Each one was seen while the quickstart's code was run, or is in Rails's own documentation.
- 01
Rails answers 422 to a POST without the CSRF token
The Rails security guide says your own non-GET requests from JavaScript need the security token as well. In the test run a POST without the
Source: Rails Guides, Securing Rails Applications, read on .X-CSRF-Tokenheader was answered422, and the log namedActionController::InvalidAuthenticityToken. The page reads the token fromcsrf_meta_tags. - 02
Without html_safe the document is escaped
The document page has to show the registered HTML unmodified. In the test, the same action without
html_safereturned<h1>Terms of Service, with every tag visible as text, so the page no longer carried the registered wording. - 03
The session cookie holds 4 kB
The pinned version IDs fit in the session with room to spare: the cookie the signup page set was 368 characters. The Rails security guide gives the limit: cookies have a size limit of 4 kB. Keep the record ID and the receipt in a table of your own.
Source: Rails Guides, Securing Rails Applications, read on .
Where are the Rails quickstart and the API reference?
Start with the quickstart: it carries every file this page excerpts, in the order you write them.
- QuickstartRails quickstartStep by step, from install to your first sealed test record, with every file and the output of each step.Open
- ReferenceAPI referenceEvery endpoint, field and error code. Sessions, records and documents are the three this page uses.Open
- Long guideClickwrap in RailsThe full registration flow: a model that stores the acceptance, a client with retries, the controllers and the webhook.Open
- GuideServer confirmationThe one place access is granted: what to compare, and the webhook that backs the check up.Open
What does Esign Comply record for a signature in Rails?
The same record on every stack and platform. Your Rails code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on Evidence and verification.
Observed and asserted fields
Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.
A signed receipt
complete()returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, andGET /v1returns it again./records /{id} /receipt An external timestamp
An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.
An offline verifier
Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source
esigncomply-verify, without an account.
Questions about e-signatures in Rails
Is there an Esign Comply SDK for Rails?
No. There is no gem, because the server SDK exists for Node.js only. A Rails app calls the REST API directly with the secret key, and the quickstart does it with Net::HTTP in one service method. The Gemfile does not change.
Where do I create the session in Rails?
In a controller action behind POST /api, with a call to POST /v1 that carries the secret key and an Idempotency-Key. The action renders only the client token, the API URL and the pinned documents as JSON.
Can the browser read the versions kept in the Rails session?
No. Rails encrypts the session cookie, so the browser carries it and cannot read or change it. The quickstart keeps the pinned version IDs there, and the confirm action compares the record against them.
Does it work in a Rails app created with --minimal?
Yes. The quickstart was run in an app made with rails new --minimal on Rails 8.1.4.1 and Ruby 3.4.13. It adds one controller, one service, one view and four routes, and needs no gem beyond what Rails installs.
Why does the document action call html_safe?
Because Rails escapes strings by default, and the page has to show the registered HTML as it is. Esign Comply sanitized that HTML when the version was published. Without html_safe the tags reach the reader as text.
Add one controller to your Rails app. Leave the record to us.
Free plan: 10 live signatures a month and a full test mode. No card required.
Rails is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Rails is from Rails's documentation or from a test run, as marked, on . /rails.md is this page as Markdown.