Solutions for the RoR-3 "Final" module. Built with Rails 8.1 on Ruby 3.3
(matching the Dockerfile).
Generated with lsphere.
The subject (v1.1) predates Hotwire and asks for jQuery / jquery_ujs /
turbolinks and hand-rolled AJAX. That toolchain is obsolete on Rails 8.
Every exercise here implements the exact same behaviour the modern,
Rails-8-native way, with no extra JavaScript library:
| Subject asks for | Implemented with |
|---|---|
| AJAX partial page updates | Turbo Frames + Turbo Streams |
| Client-side interactivity | Stimulus (notification sound in ex06) |
| Real-time / WebSockets | Action Cable via turbo_stream_from broadcasts |
| Task buffering system | Active Job (broadcast_*_later, fan-out job) |
| Authentication | Devise |
The $refresh counter trick from the subject still holds: because add / edit /
destroy / count all update through Turbo Streams, the layout <h1> is never
re-rendered in the browser, so the visible counter stays at 1.
Each exercise is a self-contained Rails app in its own directory:
| Dir | App | Feature |
|---|---|---|
ex00 |
Xnote |
Books scaffold + uniqueness; add book without reload |
ex01 |
Xnote |
destroy without reload (turbo confirm) |
ex02 |
Xnote |
edit in place (form replaces the row, shows errors) |
ex03 |
Xnote |
live book count updated on add / delete |
ex04 |
Chat |
Devise + real-time chat for all users (Action Cable + Active Job) |
ex05 |
Chat |
ChatRooms owned by their creator; messages scoped per room |
ex06 |
Chat |
real-time notifications (list + count + sound) for others' messages |
Later exercises are copies of the previous one with the new feature added.
The Dockerfile / docker-compose.yaml provide a Ruby 3.3 dev environment
(for cluster machines without Ruby). From the repo root:
docker compose run --service-ports web bash
# then, inside the container, for the exercise you want:
cd ex06/Chat
bundle install
bin/rails db:setup # creates + migrates + seeds
bin/rails server -b 0.0.0.0Then open http://localhost:3000.
- Xnote seeds a few sample books.
- Chat seeds three users (
alice@chat.dev,bob@chat.dev,carol@chat.dev), all with passwordpassword. Open several incognito windows and sign in as different users to see the real-time behaviour (and, in ex06, notifications with sound for messages from other users).
docker-compose.yaml includes a Mailpit service that captures all outgoing
email (e.g. Devise "forgot password" messages) instead of sending it.
- Web UI to read captured mail: http://localhost:8025
- SMTP endpoint the apps deliver to:
mailpit:1025inside Docker, orlocalhost:1025on the host (both configured viaSMTP_HOST/SMTP_PORT, see each Chat app'sconfig/environments/development.rb).
docker compose up starts it automatically (the web service depends_on it).
To run only the catcher: docker compose up -d mailpit. Then trigger e.g. a
password reset from a Chat app and it appears in the Mailpit UI.