Commenting in an ERB without generating a compiling error

Hello,

I have the following:

<% @projects.each do |project| %>

. <%= link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %> . <% end %>

How can I safely comment out the TD line above? Do I have to use the
=begin way?

How can I safely comment out the TD line above? Do I have to use the
=begin way?

If you don’t mind HTML comments, just wrap it in <!-- … ->

If you just want the link gone, but keep the

you can make the start
tag look like <%#= and it should work (if memory serves).

Thanks for the reply. I need to avoid HTML comments. Also, I tried

<%=

<%= link_to ‘Destroy’, project, :confirm => ‘Are you >
sure?’, :method => :delete %> %>

And what happens is every time it runs through the loop it outputs on
the page: %>, meaning the " %> from the TD is being used to
close the comment, which is why I’m trying to find out a way to
comment this line out

Thanks

because the parser see this
<%#=

<%= link_to ‘Destroy’, project, :confirm => ‘Are you >
sure?’, :method => :delete %>

and thinks i ended there
so it thinks

%> is text

put a <%#= in front of the %>

On Sep 18, 2010, at 10:50 AM, nobosh wrote:

Thanks for the reply. I need to avoid HTML comments. Also, I tried

<%=

<%= link_to ‘Destroy’, project, :confirm => ‘Are you >
sure?’, :method => :delete %> %>

And what happens is every time it runs through the loop it outputs on
the page: %>, meaning the " %> from the TD is being used to
close the comment, which is why I’m trying to find out a way to
comment this line out

This is evil, but it will work…

<%%q{

<%= link_to ‘Destroy’, project, :confirm => ‘Are you >
sure?’, :method => :delete %> }%>

The %q{…} turns everything within it into an un-evaluated string. And
the <% without the <%= results in no output. If you don’t even want the
blank line change the last %> to -%>

-philip

Thanks all, just a little surprised that Rails doesn’t have a simpilar
way to comment things out in the view.

nobosh wrote:

Thanks all, just a little surprised that Rails

You mean ERb.

doesn’t have a simpilar
way to comment things out in the view.

Sure it does:
<%# comment %>

You should probably be using Haml instead of ERb, though.

Best,

–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone

Michael P. wrote:

On 18 September 2010 22:05, Marnen Laibow-Koser [email protected]
wrote:

nobosh wrote:

doesn’t have a simpilar
way to comment things out in the view.

Sure it does:
<%# comment %>

That won’t help him comment his though…

Of course it will. He can just put the whole construct in an ERb
comment tag. ERb doesn’t pay attention to HTML nesting. Or am I
misunderstanding what you’re saying?

Or is this an issue of multiline comments in ERb? I font think it is,
but if so, then =begin or if false may be necessary.

You should probably be using Haml instead of ERb, though.

Why? What failure is the OP experiencing that HAML would make succeed?

Haml does have a nicer comment syntax, but I suggested it because it’s
generally more pleasant to work with than ERb, not due to a “failure”.

(BTW, I like HAML, but it’s this sort of exclamation of yours without
any supporting citations that seems to rile people - try rephrasing
along the lines of “check out HAML for a more succinct and easier to
read way of rendering your views rather than using the bundled Erb”…
or something).

I and others have probably said that a hundred times in this list by
now. That’s why we have archives…

Also, I didn’t want to hijack the thread.

If there’s a method in HAML that would allow him to
comment his without a lot of fussing, show that too, since that’s
the problem he’s facing.

Now that would really be hijacking the thread.

Back to the OP:

I use a fairly straightforward way of removing code from execution, in
the view, model, controller, and in whatever language I happen to be
using - wrap it in a conditional check that doesn’t return true:

<% if false %>
<%= link_to ‘Destroy’, project, :confirm => ‘Are you
sure?’, :method => :delete %>
<% end %>

Yes, that’s a very useful trick.

Similarly, if you never want an existing conditional statement to
pass, use:
<% if false && %>

and if you always want it to pass:
<% if true || %>

…easy to add and easy to remove.

Cool!

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone

On 19 September 2010 17:37, Marnen Laibow-Koser [email protected]
wrote:

Michael P. wrote:

That won’t help him comment his though…

Of course it will. He can just put the whole construct in an ERb
comment tag. ERb doesn’t pay attention to HTML nesting. Or am I
misunderstanding what you’re saying?

The original line was:

<%= link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %>

so If I changed that to :

<%# <%= link_to ‘Destroy’, project, :confirm => ‘Are you sure?’,
:method => :delete %> %>

I would be squawked at by the parser, or rather, just get an
extraneous “ %>” in my HTML, because the comment would be closed
by the first “%>”

Which is why I just tend to cut the the chase, and put an “if false”
around the lot.

@Michael P.

wow thats a good one

On 18 September 2010 22:05, Marnen Laibow-Koser [email protected]
wrote:

nobosh wrote:

doesn’t have a simpilar
way to comment things out in the view.

Sure it does:
<%# comment %>

That won’t help him comment his though…

You should probably be using Haml instead of ERb, though.

Why? What failure is the OP experiencing that HAML would make succeed?
(BTW, I like HAML, but it’s this sort of exclamation of yours without
any supporting citations that seems to rile people - try rephrasing
along the lines of “check out HAML for a more succinct and easier to
read way of rendering your views rather than using the bundled Erb”…
or something). If there’s a method in HAML that would allow him to
comment his without a lot of fussing, show that too, since that’s
the problem he’s facing.

Back to the OP:

I use a fairly straightforward way of removing code from execution, in
the view, model, controller, and in whatever language I happen to be
using - wrap it in a conditional check that doesn’t return true:

<% if false %>
<%= link_to ‘Destroy’, project, :confirm => ‘Are you
sure?’, :method => :delete %>
<% end %>

Similarly, if you never want an existing conditional statement to
pass, use:
<% if false && %>

and if you always want it to pass:
<% if true || %>

…easy to add and easy to remove.

Michael P. wrote:

On 19 September 2010 17:37, Marnen Laibow-Koser [email protected]
wrote:

Michael P. wrote:

That won’t help him comment his though…

Of course it will. �He can just put the whole construct in an ERb
comment tag. �ERb doesn’t pay attention to HTML nesting. �Or am I
misunderstanding what you’re saying?

The original line was:

<%= link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %>

so If I changed that to :

<%# <%= link_to ‘Destroy’, project, :confirm => ‘Are you sure?’,
:method => :delete %> %>

I would be squawked at by the parser, or rather, just get an
extraneous “ %>” in my HTML, because the comment would be closed
by the first “%>”

Which is why I just tend to cut the the chase, and put an “if false”
around the lot.

Ah, yes. Hadn’t thought about the extra %>. Duh. I should have read
more carefully; sorry.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone