An updated version of this post can be found 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. We are going to use Stimulus to […]
Category: ruby on rails
Stimulus.js Tutorial: How Do I Drag and Drop Items in a List?
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’s start with our simple ordered list in html. Notice that each item has a id associated […]
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, […]
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 requests […]
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. You […]
Rails apps past CRUD
I know how to build a blog in Rails with CRUD, what’s next? You’re a beginner, and you feel like you’ve reached a plateau. You’ve done all the tutorials, like how build a blog, and you want some more intermediate ideas for what to try next. You’re might also looking for a type of problem […]