Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

ruby - Block comments in html.erb templates in rails

How do you comment out html mixed with ruby code?

some text <% ... %> more text <%= ... %>
something else
<% ... %>

In jsp it's real simple: <%-- ... --%>, but I'm unable to find any concise option in rails.

Simple html comments <!-- ... --> do not work: ruby code is still executed and yells errors.

There's an option to use if false with html comments, but it's quite verbose, not to mention IDEs doesn't support it.

There's also an option coming from pure ruby, which surprisingly works.

<%
=begin %>
... html and ruby code goes here
<%
=end %>

It's generally fine, except that it's verbose, weird-looking and none of ruby IDEs I know support it (yep, I like to comment/comment-out with one keystroke).

I'm curious, is there any 'official' of doing this in rails?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use this for commenting single lines:

<%# your_ruby_code %>

For multiple lines, the

<% 
=begin %>  <% ruby_code %>
<% 
=end %>

What you said would work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...