ERb bug in comment handling?

M

Mark Volkmann

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

The time in one hour will be <%=3D 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 <%=3D 1.hour.from_now %-->

It complains that I have an unterminated string.

Does ERb not know how to parse HTML comments?

--=20
R. Mark Volkmann
Partner, Object Computing, Inc.
 
B

Brad Wilson

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

Gavin Kistner

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. 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 %>
 
J

James Edward Gray II

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

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
 
L

Lothar Scholz

Hello Brad,

BW> This looks like the correct behavior to me. The HTML comment should
BW> 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top