DEV Community

Cover image for What is hotwire with RoR?
Randy Steele
Randy Steele

Posted on

What is hotwire with RoR?

Introduction

Earlier this year the creator of Ruby on Rails, David Heinemeier Hansson (aka DHH) spoke at a conference in Chicago and discussed a new framework he helped to created called "Hotwire". DHH stated that Hotwire is "an alternative approach to building modern web applications without using much JavaScript." Hotwire is described as "HTML over-the-wire" therefore it generates HTML instead of JSON and delivers it to the server.

Why Use Hotwire

I've been researching Hotwire lately and I asked myself this question: "Why use Hotwire instead of JavaScript or a JavaScript framework or library?" This is what I have determined.

  • It's a great option for full-stack development. I don't think it's any secret that a lot of programmers were using Rails as a backend only for an application. I think with the release of Hotwire, DHH is attempting to make Ruby on Rails once again, more relevant for full-stack web development.
  • Hotwire comes with something called Turbo. Turbo uses complementary techniques to dramatically reduce the amount of custom JavaScript that most web applications will need to write. Turbo makes links and forms submissions quicker by removing the need for full page reloads.
  • While Turbo handles at least 80% of the interactivity that would typically be handled by JavaScript, you may find yourself in a situation where you need a small amount of JavaScript code, in that case, Stimulus is available. Stimulus uses an HTML-centric approach to state and wiring.

So, how do I get Hotwire?

The first step I'd recommend is going to Hotwire For Rails On Github
Installation:

  1. Add `hotwire-rails gem to your Gemfile.
  2. Run bundle install
  3. Run `hotwire:install Hotwire also has the following resources available: Hotwired Turbo Rails Hotwired Stimulus-rails

Final Thoughts

I think Hotwire is a good option for programmers that's don't necessarily love working with JavaScript. I think the folks that think Rails is "too slow" and "can't scale" may give Hotwire a shot and see what they think of it. I also like the fact that you can use a tiny bit of JavaScript when needed by way of Stimulus.

Have you used Hotwire with Rails? Let me know what you think!

Top comments (1)

Collapse
 
janmpeterka profile image
Jan Peterka • Edited

I am learning Turbo with Flask (thanks to turbo-flask). The connection is in early stage, but already I could get rid of multiple Stimulus controllers and simplified my templates immensely (partly thanks to need to split them into more partials for server-side rendering). As a mostly backend dev, needing to do full stack on my hobby projects, I just love how clean, readable and simple it is (after you understand basics).