In the example code I gave, by default in Rails with Postgres (which supports MVCC) you'll still get the error. So it's not as simple as using a transactional database: you either use a trick like this one, an row-based version column, or you need to change your isolation levels which has other performance issues.
That introduces external dependencies though. Also, since the update has to occur anyway, I'd bet that my solution is faster than also making a call to another database for a lock.