开发者

Commenting something out in Ruby ERB within the UI?

开发者 https://www.devze.com 2023-03-08 06:31 出处:网络
I have a .html.erb page and I am tryi开发者_开发问答ng to comment something out using traditional HTML comments:

I have a .html.erb page and I am tryi开发者_开发问答ng 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.


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

<%-# @User.uid %>

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


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 %>
-->


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 %>
0

精彩评论

暂无评论...
验证码 换一张
取 消