What is the meaning of erb? What is the meaning of erb? ruby-on-rails ruby-on-rails

What is the meaning of erb?


erb stands for "Embedded RuBy". A .html.erb or .erb.html file is HTML with Ruby code embedded in; Rails will evaluate the Ruby to add content to the file dynamically, and will output a "pure" HTML file for rendering.


As @Chowlett mentioned before, erb stands for Embedded Ruby. When you define any file as ".html.erb" that means it's an HTML file with ruby code embedded in it and it is similar to ".rhtml" extension of rails file.

You can see a detailed and nice difference between ".html.erb" and ".rhtml" Click Here

Same as ".rhtml", you can also rename ".rjs" extension to ".js.erb" or ".rxml" to ".xml.erb"

This format separates out content type from template engine which is "erb" in this case.


From Stuart Ellis's An Introduction to ERB Templating:

ERB (Embedded RuBy) is a feature of Ruby that enables you to conveniently generate any kind of text, in any quantity, from templates. The templates themselves combine plain text with Ruby code for variable substitution and flow control, which makes them easy to write and maintain.

Although ERB is most commonly seen generating Web pages, it is also used to produce XML documents, RSS feeds, source code, and other forms of structured text file. It can be extremely valuable when you need to create files which include many repetitions of a standard pattern, such as unit test suites.

The main component of ERB is a library which you can call within your Ruby applications and Rake tasks. This library accepts any string as a template, and imposes no limitations on the source of the template. You may define a template entirely within your code, or store it in an external location and load it as required. This means that you can keep templates in files, SQL databases, or any other kind of storage that you want to use.

Ruby distributions also include a command-line utility that enables you to process templates that are held in files without writing any additional code. Logically, this utility is called erb.

ERB is part of the Ruby standard library. You do not need to install any other software to use it.

The original article contains more detail and a short guide to using ERB. You can also read the official docs.


Note: the quoted block above was previously posted as an answer by another user without linking to An Introduction to ERB Templating or acknowledging that it was not that user's work. That post was (rightly) deleted for plagiarism. However, I thought it was a useful answer, so I've reposted the quote giving proper attribution to Stuart Ellis, the original author.