Skip to content

Blogging On Rails

Everything on Rails!

Where do I store my state in Stimulus.js?

An updated version can be found here. Stimulus.js allows for a myriad of ways to store state about our webapp. One thing to always keep in mind is that Stimulus.js wants to enhance existing HTML instead of control all of the page’s DOM, so we will need to think of ways that leverage server generatedContinue reading “Where do I store my state in Stimulus.js?”

Stimulus.js Tutorial – Multiple Selects that Filter Enterprise Data Models

If you have a lot of records that fall into many different buckets, it can be hard to filter all of that complex data record. Thankfully, we can string together a couple select fields to filter based on multiple, disparate categories. This might be like something you’d see on a car shopping website, where youContinue reading “Stimulus.js Tutorial – Multiple Selects that Filter Enterprise Data Models”

Modeling More Complex Datasets In Rails

Let’s say your company manages books. And not like account records, but perhaps books in a store, or a catalog of books available to check out. Books present a more complicated data model because there are so many of them! And there are many attributes that you might want to track, starting with the titleContinue reading “Modeling More Complex Datasets In Rails”

Let’s create a Trix Editor plugin using Stimulus.js

I’ve been working on an app that uses Trix to edit a very complicated book text. Someone asked if I could add the ability to choose different sizes of text while they are editing the book. After digging around online, I came across this example from Javan, one of Trix’s creators: https://codepen.io/javan/pen/EPqzZo. This was exactlyContinue reading “Let’s create a Trix Editor plugin using Stimulus.js”

Don’t accidentally walk away from your Active Storage Uploads with Stimulus.js

I’ve recently been using Active Storage, and it has a really neat feature called Direct Uploads. Active Storage asks your app for a URL for uploading each file, and then proceeds to upload the file directly to your storage service, without having to tax your app server’s processor. But if you’ve selected a lot ofContinue reading “Don’t accidentally walk away from your Active Storage Uploads with Stimulus.js”

Stimulus.js Tutorial – Don’t Lose Unsaved Form Fields

You may shudder remembering that long form you were once filling out, only to accidentally click a link, or refresh the page. You lost everything, all your unsaved form entries, and then you had to redo your work and fill out the form again. Don’t let your customers fall into the same trap. There areContinue reading “Stimulus.js Tutorial – Don’t Lose Unsaved Form Fields”

Stimulus.js Tutorial: Implementing Radio Selection In A Form

Let’s say your building a really fancy UI, and you don’t want to use plain old radio buttons in your form. You might have a list of items, and you’d like your customer to select one of them. You also don’t want them to submit the form without selecting an item. Here’s an example ofContinue reading “Stimulus.js Tutorial: Implementing Radio Selection In A Form”

Let’s Make an Editable Header using Stimulus.js

Stimulus excels at adding sprinkles of interactivity to your web apps. Let’s say you want to make an element on your page editable, like a todo entry, or a title for your blog page. We can use a Stimulus controller that will listen for a double click event, insert an input tag that looks justContinue reading “Let’s Make an Editable Header using Stimulus.js”

Stimulus.js Tutorial: How Do I Remotely Update My Model from a checkbox?

An updated version of this post can be found here: https://onrails.blog/2024/03/06/stimulusjs-tutorial-update-model-with-checkbox-using-turbo-morphing/ A previous update was here: https://onrails.blog/2020/11/09/updated-tutorial-how-do-i-update-my-model-from-a-checkbox/ First, I’m going to assume you’ve read the Stimulus handbook, cover to cover, like I have. Let’s say you have a Todo app, with a model Todo that has a string title, and a boolean field, completed. WeContinue reading “Stimulus.js Tutorial: How Do I Remotely Update My Model from a checkbox?”