Sunday, November 23, 2008

erb comments causing rendering issues

So as I was working on Project Unblowuppable (and learning Ruby on Rails along the way), I was trying to figure out how to put comments to myself in my ERb templates.

First attempt:

<!-- TODO: something -->

This worked, but left my comments in the rendered HTML. I didn't want to potentially expand my attack surface by leaving crumbs for hackers about incomplete/broken features.

So, take two:

<% #TODO something else %>

Better! This seemed like essentially a no-op, so I'd have the comments in my code (and could search for them) but they wouldn't render. This worked great on my dev machine, but then when I switched to a prod server all kinds of stuff broke. :(

I thought about it for a while, asked The Oracle, and finally figured out that maybe putting strings in my ERb tags (with no code) would work. So third time's the charm (I hope):

<% "TODO something else" %>

Deployed this out to prod, and after a little head scratching because mongrel didn't restart properly, everything worked! I'm a little concerned this may not be an optimal solution--Ruby is probably doing some work to create those throwaway strings, and maybe even more work since I'm using double quotes. (I realized I had some contractions, hence single quotes, in some of my comments, i.e. This doesn't fucking work! so it was easier to just put them all it double quotes than track those down. Used a regex to globally fix everything, boom--done in a few seconds. So I dunno if this is a good fix, and I wish there were a better way to do it, but The Google didn't come up with anything promising in a quick search.

0 comments: