Filtering Data in HOTWire
On Rails
by john
6d ago
When we have a long list of Todos, sometimes we want to filter them by name. We can easily do this using Turbo’s morphing and a Stimulus controller to update the page from the server. One previous way to get this interactivity was to use a Stimulus controller that filtered the HTML. This still works, and might be a strategy depending on your situation. This technique will send the request to the server, and leverage the Database to perform the filtering. This might work better if you have pagination, or don’t want to load hundreds or thousands of records onto a page to perform filtering. Filt ..read more
Visit website
HOTWire & Turbo Tutorial: Animated Deletions and Insertions
On Rails
by john
2w ago
With the addition of the new Todo form appearing at the bottom of the Todos, and the delete action removing a Todo, we have a very functional app. It would be nice if those additions and removals had a little animation to emphasize what’s happening on the page. If there was a long list, we might miss the deletion, especially if a network request caused a delay in the removal of the Todo. We can hook into Turbo streams, and run some animations on these actions to make them appear and disappear. Not animated vs. animatedAdding a Custom Turbo Action Turbo allows for the addition of custom action ..read more
Visit website
HOTWire: Where do I store my HTML state?
On Rails
by john
2w ago
We’re used to storing all of our data in the database, and letting Active Record pull it out, Action View to format it, and Action Controller to manage the request and response. But when we want quick client side interactivity, sometimes we need some extra data annotations on the HTML side that we can use without needing to communicate with the server. Most of this data is used by Stimulus, but Turbo has a few tags that can be useful. <head> State Other Javascript frameworks, like Vue.js, React, and Angular, typically generate HTML on the client side, in Javascript. We can use the fact w ..read more
Visit website
HOTWire: Considering Morphing or Turbo Frames
On Rails
by john
2w ago
With the new morphing features in Turbo 8, you now need to decide on when to use Turbo streams or Turbo frames instead of full page refreshing. Thankfully, all three techniques work together. Let’s take the Todo app that we’ve been working on, and see where using Streams or Frames makes sense. https://youtu.be/y08mnpYrDmA Turbo Streams for a new Todo form The current new Todo interaction is a new page when clicking the New Todo button on the top of the page. If we add the data-turbo-stream attribute, the GET request now appears to the server as a TURBO_STREAM request. The response, new.turbo_ ..read more
Visit website
Stimulus Tutorial: Moving & Animating Todos
On Rails
by john
1M ago
Drag and drop functions are a fun interaction, but they may not be the best interface in every situation. Buttons are a great affordance, and we can hook them up into our existing drag and drop code without any issue. Then we’ll look into animating the movement on the page so that it still feels interactive. Demo of the movement when clicking the up and down buttonsAdding Buttons On the right side of each Todo row, let’s add an up and down arrow button. These will get their own actions, moveUp and moveDown on the Stimulus controller that will be refactored into moving the Todo up and down, an ..read more
Visit website
HOTWire Tutorial: Listening for changes over ActionCable
On Rails
by john
1M ago
Many of the changes in Turbo 8 are incredibly promising for improving the perception of speed and interactivity on our web apps. A lot of my Stimulus Tutorials need an update since they were first written, so follow along to update existing tutorials and rethink them with the newest tools available. Today we obsolete the tutorials Grabbing ActionCable with Stimulus.js and Subscribing to many channels in ActionCable. Moving on from the Stimulus controllers The initial tutorials required creating a Stimulus controller and calling the ActionCable code to setup the web socket connection. Now, Tu ..read more
Visit website
Hotwire Tutorial: How Do I Drag and Drop Items in a List?
On Rails
by john
1M ago
If you’ve been following the changes in Turbo 8, it looks incredibly promising for improving the perception of speed and interactivity on our web apps. A lot of the Stimulus Tutorials could use an update since they were first written, so I thought it would be good to over existing tutorials and rethink them with the newest tools available. Join me as we rebuild the Stimulus Tutorial “How do I Drag and Drop Items in a list Quick demo of Drag and Drop functionalitySetting Priority We’ll build off the previous example and add a priority order. This will be used sort the Todos. $ rails g migrati ..read more
Visit website
Stimulus.js and HotWired Tutorial: Update Model with Checkbox using Turbo Morphing
On Rails
by john
1M ago
If you’ve been following the changes in Turbo 8, it looks incredibly promising for improving the perception of speed and interactivity on our web apps. A lot of the Stimulus Tutorials could use an update since they were first written, so I thought it would be good to over existing tutorials and rethink them with the newest tools available. Join me as we rebuild the first Stimulus Tutorial, and it’s updated version, “How do I Remotely Update My Model from a checkbox”. First, start by creating a fresh Rails app. I’m using Rails 7.1 and Ruby 3.3. $ rails new todo_app -c tailwind We need to upd ..read more
Visit website
Displaying Progress in a Long Running Background Job using HOTWire
On Rails
by john
1y ago
Fast UIs need to feel like a lot is happening, even if that’s in the background and out of site of your user. On a mobile app, usually that means moving network calls outside the “main thread” and into a background thread that calls back. On websites, it means making every request back to the server as short as possible, and then waiting for some update back from the server. This could be accomplished by polling the server, but with ActionCable and Turbo Streams, you can let the server do whatever background work is needed and have it push those updates to you. One example is processing CSV fi ..read more
Visit website
Adding Loading Screen with Turbo
On Rails
by john
1y ago
One great aspect of Turbo frames is lazy loading. You can use this behavior to quickly load in the shell of a UI, and then lazy load all the data. Adding an animating loading status will help give the feeling of immediacy and “a lot of work is happening in the background” without the frustration that the page is stuck. We don’t even need any extra Javascript, since we can animate the page with CSS. Loading many books This tutorial will start from a previous example, Modeling More Complex Datasets, which used a Book model. We’ll start from scratch with a fresh Rails app and use TailwindCSS for ..read more
Visit website

Follow On Rails on FeedSpot

Continue with Google
Continue with Apple
OR