Posts tagged with “ruby”

Pry is an interactive console, like IRB, which can be used to pause execution and inspect the current scope in your Rails web requests or tests. I'm going to show you how simple it is to drop it into your Rails apps and get better visibility over bugs.

Read the rest

The very first gem I ever created was actually pretty good. Apart from one thing: when you installed it, it didn't install the dependencies (i.e. the other gems that it depended upon). This might seem like a pretty big oversight, and it was, but there's a good reason. I actually did specify the dependencies - I just did it in the wrong place.

Read the rest

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

The other day, I was in the position where I had to recompile Vim (and GVim) on Ubuntu. I had installed the version from aptitude, which is perfectly good apart from the fact that it requires and installs the ruby 1.8.7 package. I actually use RVM for my ruby binary management, and I wanted to tell Vim to use the ruby 1.9.3 installed on my system via RVM.

Read the rest