5

I am new to ruby and rails altogether. The tutorial I am following doesn't explain the difference between <% and <%= tag. For exmaple:

<% @statuses.each do |status| %>
  <tr>
    <td><%= status.name %></td>
    <td><%= status.content %></td>
    <td><%= link_to 'Show', status %></td>
    <td><%= link_to 'Edit', edit_status_path(status) %></td>
    <td><%= link_to 'Destroy', status, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  </tr>
 <% end %>

The loop opens up with just <% and within it the tags open up with <%= .

So what's the difference?

Thanks

Jason Kim
  • 18,102
  • 13
  • 66
  • 105
tom selleck
  • 194
  • 2
  • 14
  • 1
    [This](http://guides.rubyonrails.org/action_view_overview.html#erb) – Zabba Dec 19 '13 at 23:43
  • 1
    This is not specific to Rails, but also the case for other templating languages such as jsp, asp which also use <%= %> and <% %> format. – aarti Dec 20 '13 at 00:14

1 Answers1

16

<% %> and <%= %> both execute Ruby code.

<% %> will execute Ruby code, but will not render the return value into html. <%= %> will execute Ruby code, and will render the return value into html.

Jason Kim
  • 18,102
  • 13
  • 66
  • 105