Verb
All integrations

Verb for Rails

Add an AI agent to your Rails app

Quick answer

Paste Verb's script tag into app/views/layouts/application.html.erb just before </body>, add a controller action that signs current_user's id with OpenSSL::HMAC and urlsafe base64 without padding, and hand the token to the widget. The agent then does what your users ask through your existing routes, as them, confirming before any change.

Rather not do it by hand? Your coding agent can: see Verb for Claude Code or Cursor.

1. Add the script tag

Put it in app/views/layouts/application.html.erb, just before </body>, once. Your site key is in the dashboard.

HTML
<script src="https://api.askverb.com/v1/verb.js"
        data-verb-site="YOUR_SITE_KEY" defer></script>

If you send a Content-Security-Policy, it lives in config/initializers/content_security_policy.rb: add https://api.askverb.com to script_src and connect_src.

2. Mint a token on your server

Verb treats every visitor as anonymous until your server says who they are. Sign the logged-in user's id and a short expiry with the key from your dashboard. Both halves are base64url without padding: standard base64 is the one mistake that fails every token while looking right in a log.

ruby
# app/controllers/verb_controller.rb
# routes.rb: get "/api/verb-token", to: "verb#token"
require "openssl"
require "base64"

class VerbController < ApplicationController
  def token
    return head :unauthorized unless current_user

    claims = { sub: current_user.id.to_s, exp: Time.now.to_i + 900 }

    # padding: false is not optional. A trailing "=" fails the signature check.
    body = Base64.urlsafe_encode64(claims.to_json, padding: false)
    sig  = Base64.urlsafe_encode64(
      OpenSSL::HMAC.digest("SHA256", ENV.fetch("VERB_SIGNING_KEY"), body),
      padding: false
    )

    render json: { token: "#{body}.#{sig}" }
  end
end

3. Hand it to the widget

javascript
const getSessionToken = () =>
  fetch("/api/verb-token", { credentials: "same-origin", cache: "no-store" })
    .then(r => r.json())
    .then(({ token }) => token);

// Sign in now, and let the widget ask again when the token gets old.
window.Verb.configure({ getSessionToken });
getSessionToken().then(token => token && window.Verb.identify(token));

// And wherever your app signs somebody out:
// window.Verb.reset();

The widget asks for a fresh token before the old one expires, and clears the conversation when a different person signs in. The identity docs cover the details.

4. Describe what it may do, then test it

List the actions in a verb.md: each one says whether it reads or writes, and anything that writes asks the user for a yes with the real values first. Every site comes with a test site that only answers on localhost, so you try it against your development data before your users see it. Actions that need your app's own client go through an adapter.

Frequently asked questions

Will Rails's CSRF protection block the agent's actions?

Reads are unaffected. For changes that go to CSRF-protected routes, mark those actions run: adapter, so they go through the same JavaScript your pages already use, which sends the X-CSRF-Token header. A plain browser action does not add it, and Rails would refuse the request.

Does it work with Turbo and Hotwire?

Yes. The script sits in the layout, which Turbo keeps across navigations, so the agent stays open as users move between pages.

Do I need to change my Rails backend to add Verb?

Only one small endpoint that signs who is logged in. Everything the agent does goes through the API your app already has, as the signed-in user, so your existing routes, permissions and validation stay exactly as they are.

What happens if I skip the token step?

Reading works and every change is refused, because Verb treats every visitor as anonymous until your server says who they are. Users see an honest "you need to sign in" even though they are, which is the sign the token step is missing.

Other stacks

Give your Rails app its own AI agent

Integrated in under an hour in most cases. Start with a free 30-day pilot, then we price it on what it actually does for your users.