I had a miniature programming challenge earlier today, creating an algorithm to manipulate an array of integers in Ruby. The array can be any length, but it needed to be modified to contain a maximum of, say, 5 elements. So, if the array length is less than 5 just return it, otherwise do something so reduce it to exactly 5 elements. Also, the order had to be maintained (apart from elements that have been removed).

Read the rest

I've been involved in writing a rake task to migrate an old database schema to a similar but new schema in a Rails project. The new schema was similar enough that we could carry across all the primary keys from the old tables, and it saved a lot of time to re-use them. However, the problem with doing this is that the auto increment sequence does not get updated when you add a value - you have to manually reset it.

Read the rest

I'm currently working on a Ruby on Rails project where sub-domains come into play pretty heavily. Each account created on the site has its own sub-domain, which means that there is no pre-set list. I ran into some problems when writing functional tests and integration tests with Capybara, as I had no idea how to set the current domain and assert a change in sub-domain. Fortunately, after struggling through for a couple of hours, I found the solution and I'm putting it here for the benefit of anyone else!

Read the rest

I've set up Nginx with Phusion Passenger to run my Rails apps in a development environment, as opposed to running rails server in a terminal every time. Setting the rails environment variable to "development" means that many code changes can be automatically integrated without a server restart, but every so often a full restart is required.

Read the rest