Undefined method render’ for SomeTemplate

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

I was given the task of upgrading our internal wiki from Redmine 1.1 to Redmine 2.2. I ran into a bug:

undefined method render’ for burndown_charts

This was 2 months ago. I searched all over the internet for info on this and found very little. But I now notice that Taryn East has run into exactly the same problem:

I recently had to scratch my head over a strange exception message I’d never seen before:

undefined method `render’ for #
The problem was, it came with *no* application trace at all… just the usual Rails stack-trace.

I had to guess at where the problem came from by grepping for SomeTemplate in the controller-action that had exploded, and came across the following line of code:

@template = SomeTemplate.new(params[:some_template])
Now SomeTemplate is a model of ours, and prior to this error occurring that line of code had been:

@temp = SomeTemplate.new(params[:some_template])
I have a strong aversion to calling any variable “temp”, because my reaction to seeing a variable called temp is to say “a temporary what?” not “oh, that’s an instance of a template”, and if I’m getting the wrong idea when I look at a variable name – that’s an indication it should be changed.

So I renamed it…

Unfortunately, it turns out that @template is a magic variable in Rails that refers to the template to be rendered in a given controller action.

Taryn has vastly more experience than I when it comes to Rails, so I think she had a more comfortable time fixing the problem. I work in a lot of languages but only occasionally do i work in Rails — so for me, if I hit a bug that isn’t well described on StackOverflow, it is nearly certain that I’m about to lose a day.

Source