Skip to the content.

CafeCar

CI Gem Version License: MIT

🚀 Live demo → — a back-office rendered from plain models (clients, invoices, articles, users, notes). No signup; the data resets periodically.

CafeCar is a composable view extension for Rails — presenters that format any value, a form builder that renders typed fields from the schema, UI components, Pundit policies that drive what renders, and a query grammar on every model. Use each piece wherever it deletes view code, customer-facing pages as much as the back office.

The pieces also compose all the way up: one line of controller code renders index, show, new, and edit straight from the model, with authorization, filtering, keyword search, sorting, pagination, CSV export, and Hotwire-ready forms. Every default can be overridden application-wide or per model.

A CafeCar admin rendered straight from the model: an invoices index with sortable columns, currency formatting, association links, sender avatars, and pagination — no view code.

A complete admin index — sortable columns, formatted values, association links, and pagination — rendered from a model with one line of controller code. Try the live demo →

Using ViewComponent or Phlex? They pick the unit of reuse for the UI you write; CafeCar renders the CRUD boilerplate you’d otherwise hand-write. They sit at different layers and compose — keep your components for the screens you customize and drop them into a CafeCar view like any other partial.

Install

# Gemfile
gem "cafe_car"
$ bundle install
$ rails generate cafe_car:install

The pieces, on any page

The installer includes CafeCar::Controller in ApplicationController, so the presenters and form builder work in every view — no cafe_car macro required:

<%# a customer-facing page — before, and after %>
<p>Total <%= number_to_currency(@order.total) %></p>
<p>Total <%= present(@order.total, as: :currency) %></p>

<%= form_with model: @review do |f| %>
  <%= f.field :rating %>
  <%= f.field :body %>
  <%= f.submit %>
<% end %>

One line to a working admin

class ProductsController < ApplicationController
  cafe_car
end

When a resource deserves the full CRUD surface, that single line gives you all seven RESTful actions, Pundit authorization, filtering, keyword search, sorting, pagination, CSV export, and JSON / HTML / Turbo Stream responses. Or scaffold a complete resource at once:

$ rails generate cafe_car:resource Product name:string price:decimal description:text

Learn more


Released under the MIT License.