Skip to content

Blogging On Rails

Everything on Rails!

Stimulus + Trix: Convert Emoji Short Codes To Unicode Characters On The Fly

Let’s Add an Emoji Converter to Trix with Stimulus We’ve been exploring using Stimulus to add interactivity to our apps. Let’s use Stimulus to watch for typing changes, and convert an emoji short code into the actual glyph, such as :smiley: to 😀 Getting Started I’ve uploaded my code to Github, so you can followContinue reading “Stimulus + Trix: Convert Emoji Short Codes To Unicode Characters On The Fly”

Is using Webpack in Rails worth it?

If you’ve been paying attention to the larger development ecosystem, Javascript is the rage. For example, ”GitHub is home to open source projects written in 337 unique programming languages—but especially JavaScript.“ There are many Javascript frontends available, and even the backends are written in Javascript. But if you love Ruby like I do, using moreContinue reading “Is using Webpack in Rails worth it?”

Stimulus.js Tutorial: Listening to onScroll Events for a Sticky Table Header

In one of my projects, I had a table with a lot of rows of uniform data. I started using a JQuery plugin called Sticky Table Headers. It worked really well, but I’ve been experimenting with moving different components of my code to Stimulus, where it made sense, so I thought I’d try to replicateContinue reading “Stimulus.js Tutorial: Listening to onScroll Events for a Sticky Table Header”

Stimulus.js Tutorial: How do I filter data in a list or table?

Let’s work off the previous Todo tutorial and add a way to filter those Todos using just Stimulus. We will only need to work on the todos/index.html file, and to add one Javascript controller. This example will highlight how Stimulus enhances your server rendered HTML, without the need to build complicated constellations of Javascript objects.Continue reading “Stimulus.js Tutorial: How do I filter data in a list or table?”

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?”

Stimulus.js Tutorial: How Do I Drag and Drop Items in a List?

There is an updated version that takes advantage of HOTWire and Turbo 8 Changes here. You’ve heard about Stimulus in the DHH press tour. You’ve read the Stimulus Handbook. How about a more complicated example than what you’ve seen? Here’s a tutorial on using Stimulus to drag and drop items around in a list. Let’sContinue reading “Stimulus.js Tutorial: How Do I Drag and Drop Items in a List?”

How Do I Authorize Only the Creator of a Post to Update or Delete it?

Let’s say your Rails app has an ActiveRecord data type, Post, and you want to only authorize the creator of that Post, who is of type User, to update or delete the record. One way to prevent the wrong User from editing the Post is to keep track of the creator with a foreign key,Continue reading “How Do I Authorize Only the Creator of a Post to Update or Delete it?”

How do you get Devise working with your Rails API?

Let’s say you’re building an app on iOS, and you’ve already built an API and you’ve chosen Devise, but you’re stuck because you cannot authorize your user like you can in your web browser. What do you do? One area where where Devise seems to be lacking support is API authentication, especially with HTTP requestsContinue reading “How do you get Devise working with your Rails API?”

3 Ways to Authenticate a Client on Your API

Here are 3 ways to authenticate a client with an API that you are designing. 1. Basic HTTP Auth This is as simple as it gets. Every request includes a username and password in the API request. The API server authenticates, and will return the correct response, or will return a 403 Unauthenticated error. YouContinue reading “3 Ways to Authenticate a Client on Your API”