Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I comment out ERB in Rails? [duplicate]

I understand that commenting in rails is done with '#' but if I try to comment out ERB tags, I always run into problems

 <%= link_to "Make default", make_default_admin_state_path(state) %> 

Where would you put the '#' on this code?

I tried to put it outside the <% and it did nothing. when I put it inside, there was an error message

like image 275
Leahcim Avatar asked Dec 15 '11 04:12

Leahcim


People also ask

How do you comment out an ERB code?

%>\n <% end #____/\____/\____/\____%> . This makes the comment area obvious.

How do you comment in rails?

The Ruby single-line comment begins with the # character and ends at the end of the line. Any characters from the # character to the end of the line are completely ignored by the Ruby interpreter.

What is ERB in Ruby on Rails?

ERB is a templating engine. A templating engine allows you to mix HTML & Ruby so you can generate web pages using data from your database. ERB is Rails default engine for rendering views. Note: Rails uses an implementation called erubi instead of the ERB class from the Ruby standard library.

What does ERB do in Ruby?

ERB (or Ruby code generated by ERB) returns a string in the same character encoding as the input string. When the input string has a magic comment, however, it returns a string in the encoding specified by the magic comment.


2 Answers

<%#= link_to "Make default", make_default_admin_state_path(state) %> 

<%# %> is an ERB comment: the dangling = makes no difference, and can be left in.

like image 97
Dave Newton Avatar answered Oct 01 '22 04:10

Dave Newton


Just now I wanted to just leave a block out of the template because it was currently useless, if that's the case I suggest:

<% if false %>   this block of code won't give runtime errors..   <%= alm lkjsxajklla 10293 aslkj no problems! %> <% end %> 
like image 34
Breno Salgado Avatar answered Oct 01 '22 04:10

Breno Salgado