views:

106

answers:

6

Hi,

I have a lot of comments in Rails views.

How i can prevent rendering them ?

+2  A: 

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

Nealv
This is the way to go.
Zachary
+1  A: 

There is no easy way to do that. You can monkey patch ERB sources, perhaps, but it is a bit nerdy.

floatless
+1  A: 

I'm not a Rails programmer, but a quick but of Binging brought up this link: http://blog.brijeshshah.com/strip-tags-in-rails-javascript-and-php/

The approach he's using is one that I've used in the past where you sanitize the view's output. sanitize being the name of the function you want to use before rendering the view.

Liam
A: 

Kind of hackish, but you can wrap it in a helper method

In your view:

<% 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
Dan McNevin
+1  A: 

Maybe you can use Haml Comments: -# allow to comment your haml code without them appearing in the generated html.

kalyanji
+1  A: 

If I understand the question correctly, you're asking about Ruby/Rails comments vs HTML comments... Give this a try in your view:

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

Now try this:

<%# 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 that help?

hmasson4
Wow! Such a simple solution ! Thanks!
AntonAL