Geeks With Blogs

News JS Array .toString
Liam McLennan

Just because I like to build things, and I like to learn, I have been working on a keyboard shortcut reference site. I am using this as an opportunity to improve my ruby and rails skills.

The first few days were frustrating. Perhaps the learning curve of all the fun new toys was a bit excessive. Finally tonight things have really started to come together. I still don’t understand the rails built-in testing support but I will get there.

Interesting Things I Learned Tonight

RubyMine IDE

Tonight I switched to RubyMine instead of my usual Notepad++. I suspect RubyMine is a powerful tool if you know how to use it – but I don’t. At the moment it gives me errors about some gems not being activated. This is another one of those things that I will get to. I have also noticed that the editor functions significantly differently to the editors I am used to. For example, in visual studio and notepad++ if you place the cursor at the start of a line and press left arrow the cursor is sent to the end of the previous line. In RubyMine nothing happens.



Haml is my favourite view engine. For my .NET work I have been using its non-union Mexican CLR equivalent – nHaml.

Multiple CSS Classes

To define a div with more than one css class haml lets you chain them together with a ‘.’, such as:

.span-6.search_result contents of the div go here


Indent Consistency

I also learnt tonight that both haml and nhaml complain if you are not consistent about indenting. As a consequence of the move from notepad++ to RubyMine my haml views ended up with some tab indenting and some space indenting. For the view to render all of the indents within a view must be consistent.

Sorting Arrays

I guessed that ruby would be able to sort an array alphabetically by a property of the elements so my first attempt was:

Application.all.sort {|app|}

which does not work. You have to supply a comparer (much like .NET). The correct sort is:

Application.all.sort {|a,b| <=>}

MongoMapper Find by Id

Since document databases are just fancy key-value stores it is essential to be able to easily search for a document by its id. This functionality is so intrinsic that it seems that the MongoMapper author did not bother to document it. To search by id simply pass the id to the find method:


Rails And CoffeeScript

I am a big fan of CoffeeScript so integrating it into this application is high on my priorities. My first thought was to copy Dr Nic’s strategy. Unfortunately, I did not get past step 1. Install Node.js. I am doing my development on Windows and node is unix only. I looked around for a solution but eventually had to concede defeat… for now.


The front page of the application I am building displays a list of applications.


When the user types in the search box I want to reduce the list of applications to match their search. A quick googlebing turned up quicksearch, a jquery plugin. You simply tell quicksearch where to get its input (the search textbox) and the list of items to filter (the divs containing the names of applications) and it just works. Here is the code:



I have had a productive evening. The app now displays a list of applications, allows them to be sorted and links through to an application page when an application is selected. Next on the list is to display the set of keyboard shortcuts for an application.

Posted on Wednesday, June 16, 2010 11:53 PM | Back to top

Copyright © Liam McLennan | Powered by: