View doesn’t render when last line is commented out

I plunged into the great jungle of full time freelancing last week, and since I knew I wouldn’t have a full load right off the bat, I decided to start learning Ruby and Rails to broaden my skillset and do something productive with my extra time.

I started with RubyOnRails.org’s Getting Started guide, and after finishing the guide with a minimally functional blog system, I decided to continue building features into it. While doing that, I suddenly discovered that one of my views wasn’t rendering anything at all. I could find nothing wrong with the syntax, so I cleared the content of the file and put in only:

hello!?!?!?!?

Happily, that showed up on the page. I put back in the view’s markup and noticed/remembered the last change I had made to this view before discovering that it was no longer rendering. The very last line of the file had a link_to call that I had commented out; that was the only thing on the line:

<!-- ...other code... -->
<%= link_to "Back", articles_path %>
<%-# link_to "Edit", edit_article_path(@article) -%>

I deleted the line (so now the uncommented out link_to was the last line of the file), refreshed my browser, and voila, the view was rendering again. Now, I had commented that line out purposefully, rather than deleting it, because my intent was to move it to another view once I had finished building out an admin section. So I don’t really want to just delete the line.

I know that in general, you can run into trouble in PHP if you end a file with ?> or without a new-line character. On a lark, I decided to try adding a new-line character:

<!-- ...other code... -->
<%= link_to "Back", articles_path %>
<%-# link_to "Edit", edit_article_path(@article) -%>
 

And my view was back. Weird! But at least I can have my link and comment it out too.

About Kelly Carter

I'm a freelance web developer, doing business under the name Rainworks Web Development. I'm a skeptical technophile, voracious reader, softcore gamer, and haphazard tinkerer. I have a long-term partner, a cat, and no time for glass ceilings.

Speak Your Mind

*