Author Archives: Rob Nichols

Playing with exceptions

I’ve just been having a little play with exceptions, as a new colleague wanted to understand how different errors could be handled. There is a good description of how they work in the “Exceptions, Catch, and Throw” chapter of the … Continue reading

Posted in Ruby | Comments Off on Playing with exceptions

TreeDecorator

On a couple of my projects, I’ve wanted a dynamic tree representation of a group of objects. acts_as_nested_set and it variants (such as awesome_nested_set) work well for creating the back-end structure. There are plenty of JavaScript libraries that will help … Continue reading

Posted in Ruby | Comments Off on TreeDecorator

Rails database user

Another project, another database connection via root user with no password. This is so sloppy. It is so easy to create a project specific user in any database. If this was done more often, I wouldn’t be for ever changing … Continue reading

Posted in Ruby | Comments Off on Rails database user

Comments in Gemfile

I wish people would take a little time to consider the best way to arrange and comment the gem insertions in Gemfile. I am not a great fan of commenting. I believe you should code so that it is easily … Continue reading

Posted in Ruby | Comments Off on Comments in Gemfile

Initialize: keep it simple

The more objects I build, the more I am realising that I need to keep my initialize methods simple. Not doing so, leads to problems later on. The key is in the name: best practice is to keep the initialize … Continue reading

Posted in Ruby | Comments Off on Initialize: keep it simple

Output table column names to a file

I’m working on tool to transfer data from one database to another. I wanted a list of column names in a file so that I had a list I could work through. After a hunt around the MySQL docs I … Continue reading

Posted in SQL | Comments Off on Output table column names to a file

Do not put hyphens in engine names

I’m currently working on my first rails 3.1 engine and have just wasted a day or so because I put a hyphen in the engine name. The reason I did this was to be consistent with some other plug-ins I … Continue reading

Posted in Ruby | Comments Off on Do not put hyphens in engine names

Acts As Soft Delete By Field

I’ve had a bit of spare time recently, so I thought it was about time that I created a public gem. I thought about my code and decided that my soft delete system would be a good place to start. … Continue reading

Posted in Ruby | Comments Off on Acts As Soft Delete By Field

A Geek’s take on dealing with stress

Being a CFR has put me in stressful situations. Trying to resusitate someone with kith and kin look on, is demanding.* Last year I also started work carrying out bereavement support for a local hospice. The training involved in getting … Continue reading

Posted in Bereavement support, Community First Responder | Comments Off on A Geek’s take on dealing with stress

Model inhertiance

I’m working on an application with some CMS features. One requirement is that new content is moderated before being published. To enable this, some users are allocated as moderators. To achieve this I have a moderator status column which can … Continue reading

Posted in Ruby | Comments Off on Model inhertiance