Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails Syntax <% vs <%= [duplicate]

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

like image 373
tom selleck Avatar asked Dec 08 '22 10:12

tom selleck


1 Answers

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

like image 95
Jason Kim Avatar answered Dec 29 '22 00:12

Jason Kim