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
<% %>
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.
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