Recall & Review
beginner
What does the ERB tag
<%= %> do in a Rails view?It evaluates Ruby code inside the tag and inserts the result into the HTML output.
Click to reveal answer
beginner
What is the difference between
<% %> and <%# %> in ERB?<% %> runs Ruby code without outputting it, while <%# %> is a comment and does not run or output anything.Click to reveal answer
beginner
How do you write a Ruby if statement in ERB to conditionally show content?
Use
<% if condition %> to start, then HTML or ERB code, and close with <% end %>.Click to reveal answer
intermediate
What does
<%== %> do in ERB templates?It outputs raw HTML without escaping it, so be careful to avoid XSS security risks.
Click to reveal answer
beginner
How can you embed Ruby variables inside HTML using ERB?
Use
<%= variable_name %> to insert the variable's value into the HTML output.Click to reveal answer
Which ERB tag outputs the result of Ruby code into the HTML?
✗ Incorrect
The <%= %> tag evaluates Ruby code and inserts the result into the HTML output.
What does the ERB tag <%# %> do?
✗ Incorrect
The <%# %> tag is a comment in ERB and does not run or output anything.
How do you write a loop in ERB to repeat HTML content?
✗ Incorrect
Use <% for item in list %> to start the loop and <% end %> to close it, running Ruby code without outputting the loop itself.
Which ERB tag should you use to insert unescaped HTML safely?
✗ Incorrect
The <%== %> tag outputs raw HTML without escaping, but use it carefully to avoid security risks.
What happens if you use <% %> in ERB?
✗ Incorrect
The <% %> tag runs Ruby code but does not insert any output into the HTML.
Explain how to use ERB tags to insert Ruby code and output into an HTML template.
Think about which tags run code, output, or comment.
You got /4 concepts.
Describe how to write a conditional statement in ERB to show content only when a condition is true.
Remember ERB uses Ruby control flow syntax inside tags.
You got /3 concepts.