ruby

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.

Assit on GitHub – the gem is back

Assit on GitHub – the gem is back

I while ago I wrote a small ruby library for runtime assertions to use in our projects. While I didn’t use it as heavily as expected, it has been useful in debugging in the beginning. It offers the possibility to include extra runtime checks – even expensive ones – to the code, which can be disabled in production code.

I’ve moved the project to github now, and the gem is not broken anymore. This means that you can

sudo gem install averell23-assit

from gems.github.com. The old gem (assit) is still around on rubyforge for some reason, but it’ll remain on 0.0.3 forever. If you use this, better get the github version (averell23-assit) now.

Checking rails routes

Checking rails routes

I just had to debug a strange problem with the Routing in JRuby. So in case you need to test the routing mechanism “by hand” go

> jruby script/console
>> ActionController::Routing::Routes.recognize_path('/my/path', {:method => :get})
Mingle Project Management

Mingle Project Management

In my quest for the perfect project management tool, I tested out Mingle (if you want to see all those features, just browse their site).

It’s a really flexible tool and with the new version it’s really getting close to what we’d need. They got some fresh ideas, a flexible tool and lots of eye-candy. It was even easy to set up. I’d try it for real, if it weren’t for those few big gripes…

Read more…

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”.