0
0
Ruby on Railsframework~30 mins

ERB template syntax in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
ERB Template Syntax Basics
📖 Scenario: You are building a simple webpage for a small bakery. You want to display a welcome message and a list of your top 3 favorite pastries using Ruby on Rails with ERB templates.
🎯 Goal: Create an ERB template that shows a greeting message and dynamically lists the pastry names using ERB syntax.
📋 What You'll Learn
Create a Ruby array called pastries with exactly these strings: "Croissant", "Eclair", "Macaron"
Create a string variable called greeting with the exact value "Welcome to Sweet Treats Bakery!"
Use ERB output tags <%= %> to display the greeting inside an <h1> tag
Use ERB control flow tags <% %> with a for loop to iterate over pastries and display each pastry inside an <li> tag within a <ul>
💡 Why This Matters
🌍 Real World
ERB templates are used in Ruby on Rails to create dynamic HTML pages that change based on data from Ruby code.
💼 Career
Understanding ERB syntax is essential for Rails developers to build interactive and data-driven web applications.
Progress0 / 4 steps
1
Create the pastries array
Create a Ruby array called pastries with these exact strings: "Croissant", "Eclair", "Macaron"
Ruby on Rails
Need a hint?

Use square brackets [] to create an array and separate items with commas.

2
Create the greeting string
Create a string variable called greeting with the exact value "Welcome to Sweet Treats Bakery!"
Ruby on Rails
Need a hint?

Use double quotes "" to create the string exactly as shown.

3
Display the greeting with ERB output tag
Use an ERB output tag <%= greeting %> inside an <h1> tag to display the greeting variable.
Ruby on Rails
Need a hint?

Use <%= %> to output Ruby variables in ERB templates.

4
List pastries using ERB for loop
Use an ERB control flow tag <% for pastry in pastries %> to loop over pastries and display each pastry inside an <li> tag within a <ul>. Close the loop with <% end %>.
Ruby on Rails
Need a hint?

Use <% %> for Ruby code that does not output directly, and <%= %> to output values inside the loop.