↓ Skip to main content

Rails update

·1 min

It’s that time of year where I get my online orienteering system out of mothballs ready for the next JOK Chasing Sprint. My first task was to update the application to the latest Rails 2.1.2 which proved to be harder than I had anticipated. I’m used to working with enterprise software where it’s a given that you can’t break users’ existing applications.

Running a deprecation script picked up most of the areas I needed to change of which the move from built-in pagination to will_paginate required the most effort/thought. The biggest issue I encountered though was around eager loading of associations. I eventually found a posting which describes how Rails will now only honour include associations if it detects that they are not being used. In my case, a column for the included class was referred to in the conditions but wasn’t qualified by the table name which wasn’t sufficient to cause the eager loading. This then caused the where clause to fail on select. Qualifying the table name was sufficient to get it working again.

In other words. I had to change a statement like: Example.find :all, :include => [:associated_class], :conditions => ['associated_class_column < 10'] to: Example.find :all, :include => [:associated_class], :conditions => ['associated_classes.associated_class_column < 10']

Related

Ruby and Zero

·1 min
Out of the box, Project Zero supports PHP and Groovy as scripting languages but, as this developerWorks article demonstrates, extending Zero to support other languages is pretty trivial. In this instance, they show how adding support for Ruby (specifically JRuby) can be achieved with one simple class. Now Rails developers have no excuse not to take a look at Zero!

Rails Overview: View

·4 mins
Having covered the Model and Controller aspects of Rails in previous posts, that really means it has to be View next. I’ve already touched on the basics: the controller method renders a template, either explicitly or simply by exiting and allowing the default template for the action to rendered, and the attributes of the controller class setup by the action method are then available to the template.

Rails Overview: Controller

·4 mins
In the previous entry of this series I covered the model part of the MVC support in Rails. The view and controller support is very tightly linked (more so than in, say, Struts) but I’ll start with the controller just to be contrary.