37

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

Leahcim
  • 40,649
  • 59
  • 195
  • 334

4 Answers4

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

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

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
17

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 %>
Breno Salgado
  • 1,922
  • 1
  • 20
  • 26
  • 4
    This is what I use to comment out ERB. I usually add something to make the commented block stand out because this screws up the text highlighting. I like the `if false` approach because it doesn't get screwed up when there is `<% %>` inside. I usually un-indent `if false` and `end` completely and add something after. Something like: `<% if false #-----\/----\/----\/---- %> \n..\n.. <%= ..... %>\n <% end #____/\____/\____/\____%>`. This makes the comment area obvious. – DutGRIFF May 04 '14 at 21:25
1
<!-- %= link_to "Make default", make_default_admin_state_path(state) % --> 
Dominic Goulet
  • 7,983
  • 7
  • 28
  • 56
-1

you can do it like one the @Dominic Goet did.If you stuck from it you can try this one

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

or

< %#= link_to "Make default", make_default_admin_state_path(state) %> 
Ravindra
  • 1,039
  • 2
  • 12
  • 26