JavaScript for Rails Developers
Make JavaScript your second-favorite language
by Rails DesignerFor decades Ruby on Rails devs have shrugged at JavaScript, cursed at it or vowed to never use it again. But over the years, JavaScript has improved greatly. And if you want to write modern (SaaS) web apps today, there is almost no way around it.
Sure, the Hotwire tools help you tremendously to write as little JavaScript as possible, but if you want something a bit more bespoke, you need to write some JavaScript (preferably using Stimulus) by hand.
This short and focused book will help you, Ruby on Rails developer, become more comfortable writing your own JavaScript and understand the JavaScript written by others. It won't be about React or Vue (or any of the other thousands available JS frameworks), but about writing and understand JavaScript in the Hotwire-way.
The idea is to go from zero to a functional code editor in your Rails app throughout various, easy to digest chapters. This will cover everything from working with a dependency in Stimulus, to extracting logic in smaller classes, refactoring to be more readable and using more advanced features like promises.
If you have been a Rails developer who has cursed at JavaScript, this book might be for you. If you've been a Rails developer avoiding JavaScript at all costs, this book is what you need. For Rails developers who've wished JavaScript would just disappear, this book might change your mind.
Pre-order Today — $25 (50% off)
Table of Contents
This is the tentative table of contents. Let me know if you want to see a specific subject.
- Introduction
- History
- About this book
-
Tools for modern Rails app
- What is Hotwire
- What is Turbo
-
What is Stimulus
- Using external libraries
- NPM and importmaps
- Importing into a class/file
-
Using CodeMirror in a Stimulus Controller
- Understanding the DOM (Document Object Model)
- Select and modify elements with JavaScript
- Event handling and listeners
- let, const, arrow functions
- How Stimulus works behind-the-scenes
-
Extending the Controller
- Asynchronous JavaScript: Callbacks, Promises, and Async/Await
- Refactoring into classes and functions
- Error handling and debugging
-
Practical Hotwire
-
Best practices for Stimulus
- Reusability
- Small public surface
- When to use CSS, Turbo Frames, Turbo Streams or Stimulus
-
Best practices for Stimulus
- Thank you
FAQ
When will the book be published?
At this point there is the outline and only a few chapters written. My aim is early April 2025. Based on the feedback it will be earlier or later.
Is the book for beginners?
Yes, and no. If you are a Rails veteran but always steered away from JavaScript, this book might just be for you. If you are just starting out with Rails, I would recommend to focus on Ruby (and Rails) first, and then come back to buy this book.
Anything I can read or preview?
Nothing from the book yet (except the intro), but if you are curious about my writing around JavaScript and front-end code, check out these articles from Rails Designer.
Is there bulk/team pricing?
Yes, if you want to read the book twice as fast, you can buy two copies. 😅 Or want to buy copies for your whole team? Reach out for a volume discount code (starting at 5 copies).
How will the book be published?
Plan is to distribute digitally for the common formats (PDF and epub).