Tricks

Rails forms and params

Rails forms and params

Another not to self: Rails has the cool feature that you it will map all the values from your submitted forms into the params hash. And, if you create input fields that are named “something[bla]“, it will automatically create a nested hash so that you will be able to access params[:thingyform][:something].

But what if you just have a list of things that you need to submit? In this case, just name multiple form fields something[], and the params will contain an array.

git submodules

git submodules

Today’s lesson is mainly for the people who want to use the Talia source code, but it could be useful for many git users, so I’m putting it here. In our code we use git submodules a lot; they are a bit like the good old svn externals but have different quirks that are not that easy to understand. And of course neither the official documentation nor the tutorial explain it in more detail. (I’ll assume that you’re already familiar with the general concept):

Read more…

Building Mac Packages

Building Mac Packages

Since we’ll need to deploy our application soon in a Mac environment, I’m in the process of building an installer package that our partner’s local staff will be able to handle.

Usually the preferred installation (and deinstallation) method on the Mac is drag-and-drop, which is really the best method I’ve ever encountered on any operating system. But for packages that need to be integrated into the system, such as ours, Apple has a built-in-installer package mechanism.

The installer itself is not too bad, although it doesn’t even consider that you might want to uninstall anything. But the worst part is definitively the “PackageMaker” application that comes with Apples developers’ tools.

I’ve seldom seen such a sorry excuse for a tool – it will actually loose settings if you uncheck a certain box in the UI, and more fun like that.

Fortunately, I found a nifty tool called Iceberg, which let’s you build Apple-compatible installer packages. Though it’s still a bit rough in some places, it’s already richer in features and works much better than the default Apple solution. Check it out if you need to create any Mac installer package.

A little routing trickery

A little routing trickery

Documentation in Rails seems notoriously bad – the documentation appears to be painfully incomplete. Anyway, all the cool kiddies will tell you how to do resource routing; but I wanted a bit more. In particular, i wanted to have URLs that work like http://xxx/things//. Where is the id of the thing you’re watching, and is an additonal identifier that is passed to the controller. For example, you could have a rout that let’s you do http://xxx/cars/bug/green, to show you the green version of the bug.

After a little trial and error, I found that this will be possible using a route like this:

map.resources :cars do |cars|
  cars.connect ':colour', :controller => 'cars',
    :action => 'car_with_colour'
end

Which defines this in a much nicer fashion than matching the route “manually”.

Rails rendering sequence

Rails rendering sequence

Rails does a lot of “automagic” stuff, and there seems to be a lack of documentation on how the piping behind that works. For example, there’s the strange fact that you can set up variables in a template that can then be used in it’s layout… so investigated the rendering sequence a bit.