Application monitoring that helps developers get it done.
Deploy apps to servers that you own and control.
Up next, I want to explore building more advanced and interesting features into our application. Even though we're using SQLite, there's still a pervasive myth that SQLite is just a toy database engine that can't support powerful features. While it may not have all the advanced capabilities of Postgres, it's still surprisingly robust and allows us to build feature-rich applications.
In this example, we’ll explore adding tags to our posts table. Even though SQLite doesn’t support native array columns, we can still achieve the same functionality by leveraging JSON columns.
To implement tags, we:
This setup ensures that our tags behave just like a native array column, but with SQLite compatibility.
For additional data integrity, we:
These checks prevent users from accidentally adding invalid data, keeping our system clean and predictable.
With our database structure ready, we need to update our form to allow users to select tags when creating or editing a post.
Now, we update our controller to properly handle tags attributes when saving a pos we specify tags as an array parameter, which ensures Rails knows how to process array values correctly.
Now, when a user selects multiple tags and updates a post:
To show tags in the post’s view, we update our metadata partial:
However, after testing, we noticed an issue:
To prevent empty values from being stored, we use Active Record’s normalizes helper to clean the tags array.
Apply compact_blank to remove:
This ensures that only valid tag values are stored.
Now, when we:
This gives us a fully functional tagging system using a simple JSON column.
In the next video, we’ll expand on this feature by implementing a more flexible tagging system, using higher-level SQL techniques.