Rails guide

OG Image Generator for Ruby on Rails

Use og_pilot_ruby in a controller or a view to build a branded og:image URL for each request. The gem signs the payload with your API key. You print the returned URL in the layout as og:image and twitter:image. The key stays in the server environment, in OG_PILOT_API_KEY and OG_PILOT_DOMAIN. Do not call the API from the browser, and do not commit the key.

A typical show action loads the record, then calls OgPilotRuby.create_image with the template, the title, the description, an optional image URL, and the request path. Pass iat when you want the cache window tied to that timestamp. The layout then renders the meta tags from the URL the gem returned. You do not need a separate JWT service object. The gem is the signing step. Include the path when you want per-page cache and analytics context instead of one homepage image on every URL.

Integration steps

  1. Add the og_pilot_ruby gem and configure the API key and domain in the server environment.
  2. Generate the image URL where you already have the page data: a controller, a helper, or the layout if the values are assigned.
  3. Output og:image and twitter:image, with twitter:card set to summary_large_image when you want the large card.
  4. Deploy, then check the live URL so you see the card Facebook, X, LinkedIn, Slack, Discord, and WhatsApp will cache.

Templates follow the page type. A blog post, a product, an event, a podcast episode, and a generic page do not share one layout. The API documentation lists the fields for each template and the POST endpoint at /api/v1/images. If you would rather not add the gem, the same signed token works from any HTTP client. The signing still happens on the server. MCP is the path when an agent should generate or debug the image without a new controller action. Generation needs an account with an active plan. Create that account before you expect generate_og_image to succeed.

Other stacks

Next.js apps that want the metadata-file versus ImageResponse comparison should read the Next.js OG image guide. Astro layouts that inject the URL in frontmatter should read the Astro guide. WordPress sites that are not a Rails app should use the WordPress plugin. If you are choosing between a hosted API, @vercel/og, and a DIY Satori pipeline, start at the OG image API comparison. Rails is the hosted-API path: one gem, one URL, the same card the debugger can fetch.

After the tags are live, remember that social crawlers cache the image bytes by URL. Changing the record title does not refresh LinkedIn or Facebook until they fetch again. Generate with a new cache input when the artwork must change, then confirm the debugger shows the new file rather than the previous render.