0
0
Ruby on Railsframework

ERB template syntax in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A<%= %>
B<% %>
C<%# %>
D<%== %>
What does the ERB tag <%# %> do?
AComments out code, no execution or output
BRuns Ruby code without output
CRuns Ruby code and outputs result
DOutputs raw HTML without escaping
How do you write a loop in ERB to repeat HTML content?
A<% if item in list %> ... <% end %>
B<%= for item in list %> ... <%= end %>
C<% for item in list %> ... <% end %>
D<%# for item in list %> ... <%# end %>
Which ERB tag should you use to insert unescaped HTML safely?
A<%= %>
B<%== %>
C<%# %>
D<% %>
What happens if you use <% %> in ERB?
ARaw HTML is output
BRuby code runs and output is inserted
CCode is commented out
DRuby code runs but no output is inserted
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.