user1452463
user1452463

Reputation: 119

Inserting rails into HTML file

When writing an HTML file, why use <%= INSERT RAILS HERE %> vs. <% INSERT RAILS HERE %>

Upvotes: 0

Views: 141

Answers (3)

Mahesh
Mahesh

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

Someth Victory
Someth Victory

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

Dave Newton
Dave Newton

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

Related Questions