Monday, September 29, 2008

Actionview error when naming partials " _next.html.erb"

So, today I got this wonderfully cryptic error from the erb compiler:
Showing widget/profile_completeness/_next.html.erb where line #52 raised:

compile error
/[path_removed]/_next.html.erb:-3: syntax error, unexpected '=', expecting kEND
next = local_assigns[:next]
     ^
After debugging into action_view, I realized it was because I foolishly named a partial "_next.html.erb". "next" is apparently some pseudo-reserved word in action_view and if you use it, your template crashes in weird and interesting ways. I particularly like the negative line number in the error message which results from rails pre-pending code to the erb block when compiling the method used for rendering. Bug filed here. Update: Apparently, you'll run into this if you name your partial any reserved word in ruby (case, class, etc...)

No comments: