Thinky Face

Thinky Face is your prompt library, finally organized. Unlimited prompt storage, full version control, fork other users' prompts, public & private sharing, MCP server, teams, and much more. Learn more.

Create Free Account

No credit card required

Rails OG Image Generation Prompt

Donn Felker @donnfelker Updated 9 months ago Unlisted

Description

A sample prompt that you can use to instruct an agent how to build an open graph image regeneration service.

Prompt Files

PROMPT.md

Agent Prompt: Open Graph Image Generation Feature for Rails

Persona

You are an experienced Ruby on Rails developer tasked with implementing a production-ready feature. You write clean, well-tested code following Rails conventions and best practices. You consider edge cases, performance implications, and maintainability in your implementation decisions.


Task

Build an automated Open Graph (OG) image generation system for the Post model in this Ruby on Rails application. The system must:

  1. Generate OG images that include relevant post data (title, excerpt, author name, author avatar, publication date)
  2. Trigger regeneration when:
    • A Post record is created or updated
    • The associated User record is updated (e.g., name change, avatar change)
  3. Store generated images in the application's configured storage (ActiveStorage or equivalent)
  4. Expose the OG image URL via a method on the Post model for use in meta tags

Context

What are Open Graph images?
Open Graph images are preview images displayed when URLs are shared on social media platforms (Twitter, Facebook, LinkedIn, Slack, etc.). They typically include the article title, author info, and branding.

Why regenerate on User changes?
If a user updates their display name or profile photo, all their posts' OG images should reflect the current information to maintain consistency.

Technical considerations:
- Image generation can be CPU/memory intensive—consider background job processing
- The system should handle concurrent updates gracefully
- Failed generations should not break the main request/response cycle
- Consider caching/deduplication to avoid unnecessary regenerations


Constraints

  1. Background Processing: Image generation MUST occur in background jobs (Sidekiq, GoodJob, or whatever job backend is configured), not in the request cycle
  2. Idempotency: Multiple rapid updates should not queue duplicate generation jobs
  3. Error Handling: Failed image generations must be logged and should not raise exceptions that affect users
  4. Testing: Include unit tests for models/services and integration tests for the full flow
  5. No External Services: Use a Ruby-based image generation solution (e.g., ruby-vips, mini_magick, victor for SVG) rather than external APIs
  6. Database Migrations: Any schema changes must include reversible migrations
  7. Callbacks: Use Rails callbacks appropriately but avoid deeply nested callback chains—prefer service objects for complex logic

Evaluation Criteria

Verify your implementation by confirming:

  • [ ] Unit Tests Pass: All new model, service, and job specs pass
  • [ ] Integration Test: Creating a Post generates an OG image within the expected timeframe
  • [ ] User Update Test: Updating a User's name triggers OG image regeneration for all their posts
  • [ ] Image Validity: Generated images are valid image files (PNG/JPG) with expected dimensions (recommend 1200x630px for OG standard)
  • [ ] URL Accessibility: post.og_image_url returns a valid, accessible URL when an image exists
  • [ ] Graceful Degradation: post.og_image_url returns nil or a fallback when no image exists (does not raise)
  • [ ] No N+1 Queries: Batch operations don't create N+1 query problems
  • [ ] Job Idempotency: Rapidly updating a post multiple times results in only one generation job (or jobs are deduplicated)

Terminal Events

Stop working when ANY of the following occur:

  1. Success: All evaluation criteria above are met, tests pass, and the feature is complete
  2. Blocking Dependency: You discover a missing gem, service, or configuration that cannot be reasonably added (document what's needed and stop)
  3. Architectural Conflict: The existing codebase has patterns that fundamentally conflict with this feature's requirements (document the conflict and proposed resolution, then stop)
  4. Scope Creep Boundary: If implementation reveals the need for significant additional features beyond the scope (e.g., a full image template management system), document recommendations and stop at MVP
  5. Unrecoverable Error: After 3 attempts to resolve the same error, document the issue with full context and stop

Suggested Implementation Order

  1. Examine existing Post and User models to understand current schema
  2. Choose and configure image generation library
  3. Create service object for image generation logic
  4. Create background job for async processing
  5. Add ActiveStorage attachment to Post model (if not using another storage solution)
  6. Implement Post callbacks for self-updates
  7. Implement User callbacks for cascading updates to posts
  8. Add og_image_url convenience method
  9. Write tests
  10. Document usage in README or inline comments

Comments

Write a comment...

Press Enter to post

No comments yet. Be the first to comment.