A step-by-step guide to auto-generating OpenGraph social media preview images in Rails 8 without paying for third-party APIs. The approach uses a dedicated 1200x630 HTML/Tailwind card view, the Ferrum gem to take headless Chrome screenshots of that view, Solid Queue to run generation as a background job after post creation, and ActiveStorage to persist the resulting PNG. Finally, og:image and twitter:card meta tags are added to the post layout to surface the image on social platforms.

5m read timeFrom norvilis.com
Post cover image
Table of contents
STEP 1: The “Card” ViewSTEP 2: The Screenshot Engine (Ferrum)STEP 3: The Generator ServiceSTEP 4: Attaching the Image (ActiveStorage)STEP 5: The Meta TagsSummary

Sort: