Reputation: 119
When writing an HTML file, why use <%= INSERT RAILS HERE %>
vs. <% INSERT RAILS HERE %>
Upvotes: 0
Views: 141
Reputation: 6446
When we use <%= %>
it simply displays the value returned, on the html page.
<% %>
executed the code but doesn't dispaly it on the html page.
Upvotes: 0
Reputation: 4559
<%= %>
will return value and display in your page. Assume that you have person.name = 'Dark'
<%= person.name %>
will display Dark
in your web page.
<% %>
will not return any value to your page. It just embed simple ruby code. Usually used with `control statement'.
<% if person.present? %>
<span><%= person.name %></span>
<% end %>
Upvotes: 0
Reputation: 160321
<%= %>
emits a string, <% %>
runs code.
On the pedantic side, you're writing an ERb template, not an HTML file--the syntax is the same whether it's a template for HTML, JS, or whatever.
The ERB docs provide additional (but not complete) information.
Upvotes: 2