LoginSignup
53
49

More than 3 years have passed since last update.

.html.erbのコメントアウトの仕方

Last updated at Posted at 2019-06-21

みなさんは、コメントアウトしたいなという時、どのようにしていますか?
コメントアウトの仕方自体、何個かあるので、人によって様々だと思います。

html.erbで、コメントアウトしているのを見ると、<!-- -->を使っている人が多い印象を受けます。
以下の画像のように、ちゃんとコメントアウトはできます。
スクリーンショット 2019-06-21 22.21.08.png

しかし、これだと、ブラウザでページのソースコードを表示すると、このコメントアウトも出てきてしまいます。

じゃあ、どうしたらいいのか、、、

Rubyのコメントアウトを使いましょう! 
1、<%# コメントアウト %>
2、<%= begin %>コメントアウト<%= end %>
3、<% if false %>コメントアウト<% end %>

いろいろあると思うのですが、よく使われているのは、この3つかなと思います。

参照
https://ja.stackoverflow.com/questions/43321/html-erb%E3%81%A7%E3%81%AE%E3%82%B3%E3%83%A1%E3%83%B3%E3%83%88%E3%82%A2%E3%82%A6%E3%83%88%E3%81%AE%E6%96%B9%E6%B3%95

53
49
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
49