embedded ruby syntax "<%= .. %>" in rails [duplicate] - ruby-on-rails

This question already has answers here:
What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
(7 answers)
<% %>(without equal) in ruby erb means? [duplicate]
(3 answers)
Closed 8 years ago.
Am I correct with the idea below regarding ERB template? any advice would be really appreciated.
Is the embedded ruby syntax with an equal sign "<%= %>" intended to render some output? while the one without the equal sign "<% %>" doesn't.

When you use <%= %> you render the expression value to your output. While <% %> is simply to write some Ruby code that won't be rendered to final output.

Related

Ruby on Rails: What does "<%" and "<%=" mean? [duplicate]

This question already has answers here:
What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
(7 answers)
Closed 7 years ago.
What are the differences between "<%" and "<%="? How do you know which to use? I'm teaching myself and one of the tutorials I'm using listed the above symbol sets.
You must use <%= %> for instructions whose output you want to display in your view, and use <% %> otherwise.
<%= %> use to output something
<% %> use to add your conditions for example

Difference between <%= ... %> and <% ... %> Ruby on Rails [duplicate]

This question already has answers here:
What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
(7 answers)
Closed 7 years ago.
Could someone explain the difference between using <%= some_ruby_code %> and <% some_other_ruby_code %>
I'm aware that they're not equivalent but can't find a good explanation as to why.
Thanks in advance.
In ERB (Embedded Ruby), using <%= %> will both evaluate and render the evaluated Ruby within your markup, whereas just using <% %> will only evaluate the enclosed expression, and will not print anything to the erb file.
Hope it helps!
In other words, with <%= %> you execute ruby code and print the output. Using <% %> is only necessary to run the ruby code.
To clarify, this is Emebedded Ruby which you use for views pages on Rails. This might helpful for you: https://docs.puppetlabs.com/puppet/latest/reference/lang_template_erb.html

difference between <% and <%= ruby [duplicate]

This question already has answers here:
Difference between "<%=" and "<%" when mixing ruby with html?
(2 answers)
Closed 7 years ago.
I've been working through some ruby on rails tutorials, and I see that the <% %> and <%= %> symbols are used for inline ruby, but what is the difference between those two pairs of symbols?
They are generally used in embedded ruby (erb) files.
<% %> is to execute the Ruby code within brackets, <%= %> is to print output in the file.

What is the difference between these two symbols in rails [duplicate]

This question already has answers here:
What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
(7 answers)
Closed 8 years ago.
<%= -%>
<%= %>
I am confused about this. Anyone can tell me details? Thank you in advance.
<%= %> prints something into ERB template
<%= -%> prints something into ERB template and avoids line break after expression.
Take a look here for details Why many people use "-%>" instead of "%>" in Rails?

Rails: difference between <%= and <%==? [duplicate]

This question already has answers here:
What does <%== %> do in rails erb?
(2 answers)
Closed 9 years ago.
I'm looking at legacy code that has all erb interpolations with <%== ... And I've never used that before.
What is it for? What does it do differently from <%= ?
It's shorthand to output raw content.
see https://stackoverflow.com/a/5533614/2128691
<%== #content.body %>
Is exactly the same as
<%= raw #content.body %>

Resources