Articles tagged 'ruby'

Last night I learned how to convince vim that ! and ? are part of a keyword. This is awesome, because both those characters are valid characters for method names in Ruby. In particular, it now means that when I hit ctrl-] with my cursor in a method name containing a !, it will take me to the correct method definition. Let's see how. Read more…

I'm dusting off an old post this evening, since I've spent the entire day coding in Rails on a new side project. As it happens, I had the opportunity to test-drive this article to see if it still works, and it does! For bonus points, it nearly works with Rails 5-rc1, too, which is what I ended up playing with for most of the day. I've run out of time now, but sometime in the next few days, I'll update this article for Rails 5, switching from unicorn to puma — since that's what Heroku now recommend — and trying out Bootstrap v4! But meanwhile, if you've got the opportunity to bootstrap a new greenfield Rails project, give this a shot. Read more…

Today we're going to explore how to bundle up a sample Ruby on Rails application into Docker images, run containers locally in our development environment, and link the containers together so they can talk to each other. On the way, we'll automate the build with Rake, and discover a little more about how container linking actually works. Read more…

Today we figure out a novel approach to the materialised path pattern for representing hierarchical data in SQL. It takes advantage of PostgreSQL's native support for array types. But it also poses a question: can we make use of ActiveRecord's preloading machinery for eager loading these trees? Read more…

Back in part 1, we had a look at some of the new features of RSpec, and we used those features to create a query-style controller action. In particular, it listed out all the widgets in our inventory management system. This time around, we're going to look at a command-style action: creating a new widget. Read more…

RSpec has come a long way since I last used it in anger. Today, I'm starting through a worked example on test-driving a Ruby on Rails controller with RSpec, Capybara feature specs, and plenty of mocking. Along the way, we'll see some neat new features of RSpec in action. Read more…

I’ve lost track of why now, but I’ve spent a bit of time this afternoon trying to understand how the Rails logger works in production. For years we’ve been using a Hodel 3000 Compliant Logger, which is dead straightforward. Recently, though, we switched back to using the built in logger with Rails, which is a little more subtle. Read more…

Once upon a time, in a galaxy far, far away ... Ok, I'll stop now. A few years back, I was working on a client project and they needed to integrate with a billing platform. They'd already picked Protx (now SagePay) as their platform of choice, and in particular, the Server variant. Wait, I'll backtrack. SagePay has three variants: Read more…

Ruby has the Comparable module, which, if you implement the spaceship operator <=> (winner of "Best Named Operator" 10 years running!) then it will give you a bunch of comparator operators for free (<, <=, ==, >= and >). Win. Enumerable's #sort method uses the spaceship operator to do sorting too, so implementing the spaceship gives you a whole bunch of interesting behaviour pretty much for free. Read more…

Ubuntu is my Linux of choice. It has been for a long time. I've been a huge fan of Debian since the late '90s -- I was a Debian Developer stuck in the NM queue for a few years -- but the release cycle was way too long for my tastes (which invariably meant I kept most of my systems running testing or unstable). So I switched to Ubuntu pretty early on. Read more…

I was invited to give a short introduction to Ruby on Rails at Tech Meetup in Edinburgh a couple of days ago. I'd been racking my brain for days on what to talk about -- 15 minutes is too short for me to give a meaningful introduction to Rails -- and eventually settled on telling a few stories. Read more…

In a previous post, Using git submodules to track plugins I introduced the idea of using git submodules as part of your workflow in developing Rails applications. At the time, Rails itself wasn't using git, but that has finally happened. You can find the official Ruby on Rails source code repository at http://github.com/rails/rails. So, how to we track Rails with git submodules? Read more…

Since the core Ruby on Rails team is finally actually moving to git, and a whole slew of other projects are following in their wake, now seems like a good time to write up my experiences with using git sub-modules to track external dependencies. Back in the world of Subversion, I had been using Piston to track external dependencies. This allowed me to import third party dependencies from their subversion repository into my own application's repository, keep track of specific versions and even make my own local changes. Read more…

Last night I gave a wee presentation to the Scottish Ruby User Group about Capistrano 2, and some of the ways I've been working with it over the last couple of weeks, since for some reason I seem to have been immersed in it for a couple of different projects. It's nothing particularly groundbreaking, but I figured it was useful to demonstrate some of the things it's capable of, and how much easier it makes my life on a daily basis. You can find a copy of the slides here, complete with my speaker notes: Read more…

I've been using account_location for a couple of applications recently. It's a really nice way to give individual 'clients' of an application their own domain and when we come to scaling up, it's a really easy way of splitting customers across several hosts. So, yeah, very nice. And it's dead easy to deploy in the first instance -- a couple of DNS records along the lines of: Read more…