Rails
Build a JSON API for a library book reservation system. Ruby on Rails. PostgreSQL. **Models:** - Book (title, author, isbn, copies_available:integer) - User (name, email) - Reservation (user_id, book_id, reserved_at, expires_at, status: pending/active/expired/cancelled) **Endpoints:** - POST /reservations — reserve a book for a user (decrement copies_available, set 48h expiry) - GET /users/:id/reservations — list a user's reservations (paginated) - DELETE /reservations/:id — cancel a reservation (increment copies_available back) **Business rules:** - Can't reserve a book with 0 copies_available - Can't have two active reservations for the same book by the same user - Cancelling an already-cancelled reservation returns an error - All error responses use envelope: { error: { code: String, message: String } } **Deliver:** Complete working code — migrations, models, controller, routes, and request specs. Output all code inline in your response as code blocks with file paths. Do not use tools to write files — put everything in your response text. Do not ask clarifying questions — the spec is complete. Make your own design decisions and build it.
fill the variables
This prompt has 1 variable. Pro fills them into a ready-to-paste prompt for you — no manual find-and-replace.
{error: { code: String, message: String}
Unlock with Pro →when to use it
Community prompt sourced from the open-source GitHub repo croftspan/gigo (Apache-2.0). A "Rails" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
codingcommunitydeveloper
source
croftspan/gigo · Apache-2.0
more in Coding
Coding✓ tested
Senior code review (strict mode)
senior staff engineer running a merciless but fair review
Coding✓ tested
Debug by hypothesis, not by guessing
debugging partner who forms theories before touching code
Coding✓ tested
Generate tests from described behavior
test engineer who writes tests that would actually catch regressions