Avoid posting comments in HTML

I have a lot of comments in Rails views.

How can I prevent their rendering?

+5
source share
6 answers

If I understand the question correctly, you are asking for Ruby / Rails comments and HTML comments ... Try in your opinion:

<!-- This is an HTML comment and will show up in the HTML source! -->

Now try the following:

<%# This is a comment that won't show up in the HTML source! %>
<%# 
    You can even use this for commenting multiple lines!
    How useful!
%>

Does it help?

+6
source

use = begin and = end to mark the beginning and end of your comment

+2
source

. , ERB , .

+1

Rails, , Binging : http://blog.brijeshshah.com/strip-tags-in-rails-javascript-and-php/

, , - , , sanitize . sanitize - , , .

+1

, Haml : - # haml html.

+1

,

:

<% comment do %>
  <%= "this won't be executed" %>
  or displayed
<% end %>

in app/helpers/application_helper.rb

module ApplicationHelper
  def comment(&block)
    ## you can do something with the block if you want
  end
end
0

All Articles