Reputation: 17410
I have a lot of comments in Rails views.
How i can prevent rendering them ?
Upvotes: 6
Views: 1192
Reputation: 176
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?
Upvotes: 7
Reputation: 75
Maybe you can use Haml Comments: -# allow to comment your haml code without them appearing in the generated html.
Upvotes: 1
Reputation: 22336
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
Upvotes: 1
Reputation: 1768
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.
Upvotes: 1
Reputation: 13438
There is no easy way to do that. You can monkey patch ERB sources, perhaps, but it is a bit nerdy.
Upvotes: 1