Consent updates: Rails 2.3 compatibility, request expressions every which way

A brief note to point out some changes I made to Consent, my access control DSL for Rails. I’ve been doing some Rails development for the first time in a few months and ran into some things that needed changing.

First up, it seems Rails 2.3 uses application_controller.rb rather than application.rb for the root controller and this was breaking Consent’s startup routine; this is now fixed.

Secondly, Consent has for some time provided a feature to let you use request expressions in your routes and controllers, so you could write redirect_to users.login rather than redirect_to :controller => 'users', :action => 'login', for example. This has now been extended so that any controller or view method that expects a URL hash (such as redirect_to, link_to, form_for, etc.) can use request expressions instead. This really helped me clean up some template code earlier and I think I prefer it to named routes. In fact, it’s a bit like getting named routes for free without having to specify them anywhere.

Let me know if either of these cause problems; injecting method_missing so broadly is bound to upset somebody but I’ve not had any problems so far.

If you’ve enjoyed this article, you might enjoy my recently published book JavaScript Testing Recipes. It’s full of simple techniques for writing modular, maintainable JavaScript apps in the browser and on the server.