Suffix Suffix

Rendering GPS logs in Ruby

Posted on Jul 20th @ Home

For a little while now I want to plot my own GPS logs (like my last cycling trip). I am obsessed with geolocation. Sure, you can use Google Maps, the default weapon of choice these days. With their API you can plot your track log on top of their maps and satellite images. You don't even have to program that, Google Maps can render KML files out of the box and there are tons of tools out there to do the same. But I'm a programmer, loading KML files in Google is no fun. I want to learn to pl...

Form submit in a Rails functional test

Posted on Jun 27th @ Home

I'm new to testing and documentation for the built-in Rails testing seems scarce so I'll write down what I learn in the process... there may be - and probably are - better ways to do this. Submitting a form in a test In a functional test you test the controller. A controller is responsible for the incoming requests and the response with a rendered view. If you want to test the creation of an object you'll need a way to fill the form and send the data to the controller. Imagine the fo...

No more error_messages_for in Rails 3

Posted on Jun 21st @ Home

I played with the latest Rails 3 beta release today (version 3.0.0.beta4) and noticed the following depreciation warning: DEPRECATION WARNING: form.error_messages was removed from Rails and is now available as a plugin. After Googling around some I found out why. Apparently the old error_messages_for violated the core Rails principles of never dictating the look and feel of an application. Indeed, it includes fixed HTML and copywriting, not good. Solution The Rails core team decid...

Validate composite keys in Rails 3

Posted on Apr 15th @ Belighted

Suppose you have a ‘families’ table in your database with a ‘husband’ and ‘wife’ column. You add a a composite key so that the combination husband and wife is unique. You certainly don't want another record with the same husband and wife combination. At the database level your migration could look like this: add_index :families, [:husband, :wife], :unique => true Validations in Rails 2.x Now you want to add a corresponding validation in your family...