0

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

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.