2

What the difference between

<% some code %> 

and

<%= some code %> 

in RoR?

vishes_shell
  • 22,409
  • 6
  • 71
  • 81
OneZero
  • 11,556
  • 15
  • 55
  • 92

2 Answers2

9

Think of it like this:

<% execute this code and display nothing %> 

and

<%= execute this code and display the result in the view %> 

So, for example you could do this:

<% @values = ['eenie', 'menie', 'miney', 'mo' ] %>
<% @values.each do |value| %>
  The current value is <%= value %>!
<% end %>
Kevin Bedell
  • 13,254
  • 10
  • 78
  • 114
0

<%= some code %> will evaluate the statement and display it in the view. <% some code %> will only evaluate the statement.

Huy
  • 10,806
  • 13
  • 55
  • 99