ERb bug in comment handling?

(Mark Volkmann) #1

I had the following in a .rhtml file that I was using for a Rails view.

The time in one hour will be <%= 1.hour.from_now %>

This worked fine. Then I decided I wanted to comment that out
temporarily so I changed the line to this.

<!-- The time in one hour will be <%= 1.hour.from_now %-->

It complains that I have an unterminated string.

Does ERb not know how to parse HTML comments?

···

--
R. Mark Volkmann
Partner, Object Computing, Inc.

(Brad Wilson) #2

This looks like the correct behavior to me. The HTML comment should
have no effect on whether the Ruby code is executed, IMO.

···

On 8/21/05, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:

I had the following in a .rhtml file that I was using for a Rails view.

The time in one hour will be <%= 1.hour.from_now %>

This worked fine. Then I decided I wanted to comment that out
temporarily so I changed the line to this.

<!-- The time in one hour will be <%= 1.hour.from_now %-->

It complains that I have an unterminated string.

Does ERb not know how to parse HTML comments?

(Gavin Kistner) #3

ERB doesn't know anything about HTML, nor should it. I frequently write code like this:
     <!-- userid: <%=userid%> -->
as a way to put some dynamically-generated information in the HTML page that I can view in the source, but which will be hidden.

In short, what you wanted to do was either wrap a valid SGML/HTML comment around your ERB output:

<!-- <%= 1.hour.from_now %> -->

Or to simply modify your call so that the Ruby code ran, but was not output:

<% 1.hour.from_now %>

···

On Aug 21, 2005, at 11:23 AM, Mark Volkmann wrote:

This worked fine. Then I decided I wanted to comment that out
temporarily so I changed the line to this.

<!-- The time in one hour will be <%= 1.hour.from_now %-->

It complains that I have an unterminated string.

Does ERb not know how to parse HTML comments?

(James Edward Gray II) #4

Right. Erb is a general purpose templating system. Even Rails uses to for more that just HTML. Fixtures and email, just to name two examples.

James Edward Gray II

···

On Aug 21, 2005, at 12:32 PM, Gavin Kistner wrote:

On Aug 21, 2005, at 11:23 AM, Mark Volkmann wrote:

This worked fine. Then I decided I wanted to comment that out
temporarily so I changed the line to this.

<!-- The time in one hour will be <%= 1.hour.from_now %-->

It complains that I have an unterminated string.

Does ERb not know how to parse HTML comments?

ERB doesn't know anything about HTML, nor should it.

(Lothar Scholz) #5

Hello Brad,

This looks like the correct behavior to me. The HTML comment should
have no effect on whether the Ruby code is executed, IMO.

It doesn't even know that it is HTML surrounding the ruby code,
because even this maybe a false assumption.

···

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's