With this Ruby script you can print all values in a Redis database to your console (derived from this bash...
When you allow file uploads in your app, a user might upload content that hurts other users. Our primary concern...
In Ruby on Rails ActiveRecord::Relation#merge overwrites existing conditions on the same column. This may cause the relation to...
I found the linked article very helpful to refresh my understanding of database indexes. As a small bonus, it includes...
Maintaining larger projects makes it more difficult to balance refactoring and upgrade tasks according to its actual value. Consider to...
Let's say we have posts with an attribute title that is mandatory. Our example feature request is to tag...
Rails Active Support provides some helpful methods for calculating times and dates, like Duration#ago or Duration#from...
The change_column method for rails migrations support casting with a custom SQL statement. This allows us to change a...
This is a checklist I use to work on issues. For this purpose I extracted several cards related to the...
In the past we validate and set default values for boolean attributes in Rails and not the database itself.
Since Rails 7 you are able to encrypt database information with Active Record. Using Active Record Encryption will store an...
To retrieve only unique combinations of the selected attributes: You can omit rows, where all selected columns are equal with...
Using ActiveRecord's #signed_id and .find_signed methods you can create URLs that expire after some time. No conditionals...
When an object is created / updated, various callbacks are executed in this order: before_validation after_validation before_save
TLDR if you define a equality method for a class you must also implement def hash. Ruby has a lot...
tl;dr You should decouple migrations from models by embedding models into the migration. To use STI in this scenario...
ActiveType::Object inherits from ActiveRecod::Base and is designed to behave like an ActiveRecord Object, just without the database...
To allow HTTP 304 responses, Rails offers the fresh_when method for controllers. The most common way is to pass...
Greg Molnar has written a neat article about creating a single-file Rails app. This is not meant for production...
This should be fixed in the latest LTS-branches of our mysql2 fork, 0.2.x-lts and 0.3.x-lts...
SELECT pg_size_pretty(pg_database_size('some-database')); Example SELECT pg_size_pretty(pg_database_size('cards_p')); ----------------
When paginating records, we usually need to know the number of total records in order to render pagination links. Popular...
I recently wanted to add a model for address information but also wanted to add a unique index to those...
It might sometimes be useful to check whether your Rails application accesses the file system unnecessarily, for example if your...