When writing custom validators like described in the Rails guide on validations it’s good practice to write tests for them so you are sure they work as intended. Let’s take a look at the custom validator example shown in that Rails guide:| Mark's Blog
When you create a block in Ruby and execute it later it’s context is tied to where it was defined. Take a look at this very contrived example:| Mark's Blog
In PostgreSQL you can lock records while selecting them using FOR UPDATE. When using a LEFT JOIN you can run into an error if your selection includes NULL records for the joined table, to prevent this you should specify for which table(s) the records should be locked like so:| Mark's Blog
When selecting records with ActiveRecord in Rails all of the selected objects are usually loaded into memory, if you are dealing with a large record set (for example in a background job, rake task or migration) this can lead to memory problems that result in your code crashing.| Mark's Blog
To revert a commit in git you can use the git revert command, this undoes all the changes of the given commit with a new commit. But what if you only want to revert one specific file to a specific revision?| Mark's Blog
Do you ever run into that situation while coding where you need to temporarily undo some of your uncommitted changes? I sure do.| Mark's Blog
When working on Rails projects a commonly used part is the Rails router which is used to direct incoming requests to the appropriate controllers and actions and to generate paths and URLs so you don’t have to hardcode them all over the place. | Mark's Blog
When working with private keys that are protected with a passphrase on Ubuntu server you will be prompted you to enter the passphrase on each use. Just like on your desktop environment you can however use an SSH agent in which you load your keys for the duration of your session.| Mark's Blog
A while back my laptop running Ubuntu started hanging on boot after a kernel update, to make it work I had to revert to using an earlier kernel version from the boot screen. | Mark's Blog
Using modules to share code between classes in Ruby is a commonly used method to add re-usable behaviour without blocking the inheritance chain, the Rails ActiveSupport::Concern adds some convenience methods to do so. What (at least in my opinion) should not be forgotten is to test the usage of such modules on your classes, this can actually be achieved fairly easily creating a module with test code that you can then again include in your tests.| Mark's Blog