Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <% %> and <%= %> in RoR [duplicate]

What the difference between

<% some code %> 

and

<%= some code %> 

in RoR?

like image 836
OneZero Avatar asked Nov 29 '25 16:11

OneZero


1 Answers

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 %>
like image 93
Kevin Bedell Avatar answered Dec 02 '25 06:12

Kevin Bedell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!