Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Comments in erb/rthml cause incorrect formatting

#3163

Comments in rhtml/erb code can cause the parser to behave incorrectly.

For example:

  <% if true #comment %>
    <li><%= link_to "Announcements", :controller => "announcement", :action => "list" %></li>
  <% end -%>

  <li><%= link_to "Realview", :controller => "realview", :action => "refresh" %></li>

  <li><%= link_to "System Configuration", :controller => "system", :action => "configure" %></li>

Yields:

  <a href="/announcement/list">Announcements</a></li>    <----ERROR LINE

  <li><a href="/realview/refresh">Realview</a></li>

  <li><a href="/system/configure">System Configuration</a></li>

Note that the "

  • " is missing from the beginning of "ERROR LINE".

Reported by DavidT · September 8th, 2009 @ 04:34 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from new to invalid

    1) Putting # in the middle of an ERB code chunk to indicate a comment isn't supported by ERB. It used to work by accident under Ruby 1.8.6, but that's an implementation detail that changed in 1.8.7. The valid syntax for ERB comments is

    <%# comment -- ignored -- useful in testing %>
    

    see http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html and http://www.ruby-forum.com/topic/154835

    2) If you want to propose a change in ERB itself, you need to go upstream; Rails is just an ERB consumer.

    September 8th, 2009 @ 12:10 PM

  2. Ian Moss
    Ian Moss

    I get the feeling this SHOULD be possible in Rails.

    In Ruby a comment is a #

    In Rails Erb I start a Ruby block of code with <% and finish it with %>

    To me, it seems logical that anything following a # should work as a ruby comment.
    It shouldn't matter if there is whitespace before or not.

    Can someone point me towards the bit of rails core code that deals with comments, so I can fix this or branch or whatever is needed.

    I'm going to go off and search the rails git code base now - but am thinking someone may well read this before I find it.

    Thanks - Ian - http://twitter.com/oceanician

    October 28th, 2009 @ 11:33 AM

  3. CancelProfileIsBroken
    CancelProfileIsBroken

    Again, this isn't in Rails. ERB is responsible for handling those blocks. Once we hit the <% we're out of the Rails codebase.

    October 28th, 2009 @ 11:54 AM

  4. Ian Moss
    Ian Moss

    Great - I'm new to the Rails codebase, whereabouts is the ERB code?
    I've tried to search via GitHub but can't find it.
    Is their a contributors readme someplace I should be looking at ?
    Cheers,
    Ian.
    http://twitter.com/oceanician

    October 29th, 2009 @ 11:00 AM

  5. Ian Moss
    Ian Moss

    Aha - Ok so it helps understanding the R is Ruby not Rails for me :)
    Found the erb within ruby:
    http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/erb.rb?view=log1

    Ian

    October 29th, 2009 @ 11:14 AM

  6. Ryan Bigg
    Ryan Bigg
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 9th, 2010 @ 09:56 PM

  7. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 11th, 2010 @ 12:13 PM

  8. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 21st, 2010 @ 03:37 AM

  9. bingbing