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
%>\n <% end #____/\____/\____/\____%> . This makes the comment area obvious.
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.
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.
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.
<%#= link_to "Make default", make_default_admin_state_path(state) %>
<%# %>
is an ERB comment: the dangling =
makes no difference, and can be left in.
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 %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With