Ruby Language Tutorial => ERB (2024)

Table of Contents
Introduction Syntax Remarks

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:

> Step 1: Go view our video on YouTube: EF Core Bulk Insert

> Step 2: And Like the video. BONUS: You can also share it!

Introduction

ERB stands for Embedded Ruby, and is used to insert Ruby variables inside templates, e.g. HTML and YAML. ERB is a Ruby class that accepts text, and evaluates and replaces Ruby code surrounded by ERB markup.

Syntax

  • <% number = rand(10) %> this code will be evaluated
  • <%= number %> this code will be evaluated and inserted into the output
  • <%# comment text %> this comment will not be evaluated

Remarks

Conventions:

  • ERB as a template: Abstract business logic into accompanied helper code, and keep your ERB templates clean and readable for people without Ruby knowledge.
  • Append files with .erb: e.g. .js.erb, .html.erb, .css.erb, etc.


Ruby Language Tutorial => ERB (2024)
Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6097

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.