0
0
Ruby on Railsframework~20 mins

ERB template syntax in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ERB Syntax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Output of ERB expression tags
What will be rendered on the page by this ERB snippet?
<% name = 'Alice' %>
<%= "Hello, #{name}!" %>
<%# This is a comment %>
<% name = 'Bob' %>
<%= "Goodbye, #{name}!" %>
Ruby on Rails
<% name = 'Alice' %>
<%= "Hello, #{name}!" %>
<%# This is a comment %>
<% name = 'Bob' %>
<%= "Goodbye, #{name}!" %>
AHello, Alice!Goodbye, Bob!
BHello, Alice!Goodbye, Alice!
CHello, Bob!Goodbye, Bob!
DHello, Bob!Goodbye, Alice!
Attempts:
2 left
💡 Hint
Remember that <% %> runs Ruby code without output, and <%= %> outputs the result.
📝 Syntax
intermediate
1:30remaining
Correct ERB tag for Ruby code without output
Which ERB tag correctly runs Ruby code but does NOT output anything to the page?
A&lt;% ruby_code %&gt;
B&lt;%= ruby_code %&gt;
C&lt;%# ruby_code %&gt;
D&lt;%== ruby_code %&gt;
Attempts:
2 left
💡 Hint
Think about which tag runs code silently.
🔧 Debug
advanced
2:30remaining
Identify the ERB syntax error
Which option contains an ERB syntax error that will cause the template to fail rendering?
Ruby on Rails
<%= 'Hello' %>
<% if true %>
  <%= 'Yes' %>
<% end %>
A
&amp;lt;% if user_signed_in? %&amp;gt;
&amp;lt;%= 'Welcome!' %&amp;gt;
&amp;lt;% end %&amp;gt;
B
&amp;lt;% if user_signed_in? %&amp;gt;
  &amp;lt;%= 'Welcome!' %&amp;gt;
&amp;lt;% end %&amp;gt;
C
&amp;lt;%= if user_signed_in? %&amp;gt;
  &amp;lt;%= 'Welcome!' %&amp;gt;
&amp;lt;% end %&amp;gt;
D
&amp;lt;% if user_signed_in? %&amp;gt;
  &amp;lt;%== 'Welcome!' %&amp;gt;
&amp;lt;% end %&amp;gt;
Attempts:
2 left
💡 Hint
Check which tag is used to start the if statement.
state_output
advanced
2:00remaining
Value of variable after ERB execution
Given this ERB snippet, what is the value of count after rendering?
<% count = 0 %>
<% 3.times do %>
  <% count += 1 %>
<% end %>
<%= count %>
Ruby on Rails
<% count = 0 %>
<% 3.times do %>
  <% count += 1 %>
<% end %>
<%= count %>
A0
BError: undefined variable
C1
D3
Attempts:
2 left
💡 Hint
Remember that Ruby code inside <% %> runs and can change variables.
🧠 Conceptual
expert
2:30remaining
Difference between <%= and <%== in ERB
What is the main difference between the ERB tags <%= %> and <%== %> when rendering HTML content?
A<%= outputs raw HTML without escaping; <%== escapes HTML entities before output
B<%= escapes HTML entities before output; <%== outputs raw HTML without escaping
CBoth escape HTML entities before output
DBoth output raw HTML without escaping
Attempts:
2 left
💡 Hint
Think about safe HTML rendering and escaping.