Skip to content

Instantly share code, notes, and snippets.

@skanev
Created October 2, 2012 12:22
Show Gist options
  • Save skanev/3818611 to your computer and use it in GitHub Desktop.
Save skanev/3818611 to your computer and use it in GitHub Desktop.
Weird bug

I've inherited a legacy Rails app that runs on Ruby 1.8.6. I want to upgrade to 1.8.7, but I get weird bugs. One of them was a weird CSS glitch. Here's what happens:

Note how input.html.erb renders <div id="ribbon"> and then a partial. If you look at the output, the partial gets rendered in both versions of Ruby, but the <div id="#ribbon"> gets rendered only in 1.8.6. It appears that the culprit is the small fragment containing a ruby comment <% #end top div %>. If I remove it, both work the same.

Is this an ERB issue and why does switching Ruby versions trigger it?

<div id="flower"></div>
<% if slider ||= false %>
<div id="bubbles"></div>
</div> <% #end top div %>
<div id="ribbon">
<%= render :partial => 'visualisations/slider', :locals => {
:slider_data => slider_data ||= nil,
:selected_year => year.to_s,
:preload_action => url_for( :action => preload_action, :id => preload_params ||= nil ),
:before_change_func => (before_change_func ||= nil),
:on_change_function => on_change_function,
:after_change_func => (after_change_func ||= nil),
:bubble_element_id => 'bubbles',
:draw_bubbles => true
}
%>
</div>
<% end %>
<div id="flower"></div>
<div id="bubbles"></div>
</div> <div id="ribbon">
<select id="slider_year" name="slider[year]"><option value="1975">1975</option>
<div id="flower"></div>
<div id="bubbles"></div>
</div>
<select id="slider_year" name="slider[year]"><option value="1975">1975</option>
@valo
Copy link

valo commented Oct 2, 2012

I've also noticed that and blogged about it here: http://www.valentinmihov.com/2009/07/08/weird_erb_comment_functionalities/

I think that making ruby comments in ERB templates is not a good idea. No clue why is happening though.

@Mange
Copy link

Mange commented Oct 3, 2012

ERB is in stdlib, so different versions of Ruby can have different bugs. I'll probably work if you make a newline before you close the ERB block. Remember that ERB is (pretty much) gsubbed into normal ruby, so comments can ruin lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment