GeekedOut
GeekedOut

Reputation: 17185

Commenting something out in Ruby ERB within the UI?

I have a .html.erb page and I am trying to comment something out using traditional HTML comments:

  <!--
  User Id (testing MySQL call): <%= @User.uid %>
-->

But since its a Ruby reference that I am commenting out, it isn't getting commented, and is generating ruby errors. How could I comment out such a thing? I also tried putting a # before that line, but that didn't work either.

Upvotes: 2

Views: 357

Answers (3)

shoen
shoen

Reputation: 11865

You can also comment a block with =begin and =end like this:

<% 
=begin %>
<%= link_to "Sign up now!", signup_path, :class => "signup_button round" %>
<% 
=end %>

Upvotes: 0

coreyward
coreyward

Reputation: 80041

You can comment out an ERB expression by changing the <%= into a <%#. This will not hide the HTML containing it from view, but you can combine HTML comments with the ERB comment to keep your application from throwing an error and hiding the surrounding HTML bits.

<!--
User Id (testing MySQL call): <%# @User.uid %>
-->

Upvotes: 2

kafuchau
kafuchau

Reputation: 5593

In your ERB tags, to do a comment, use:

<%-# @User.uid %>

You'll still need the HTML comment tags wrapping the other text too.

Upvotes: 3

Related Questions