What is the meaning of erb?

Ruby on-RailsRubyErb

Ruby on-Rails Problem Overview


Why is the view of Rails application in the format *.erb.html? What does "erb" mean?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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.

Solution 2 - Ruby on-Rails

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.

Solution 3 - Ruby on-Rails

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.

Solution 4 - Ruby on-Rails

Embedded Ruby, also called ERb, is the primary template system for including dynamic content in web pages. --Michael Hertl

Solution 5 - Ruby on-Rails

from [template-format][1] [1]: http://www.stuartellis.eu/articles/erb/#template-format

A file that contains an ERB template may have any name, but it is the convention that the name of file should end with the .erb extension. Rails requires template files to have the extension of the output type, followed by .erb, so that a name like layout.html.erb indicates a HTML template.

erb files will simply output text. Nothing more. What text is depending on the mix of static text and ruby code inside the file. You can use erb to generate html which default usage in Rails, because that's what browsers need to display a page.

In ruby there are certain defaults One default is that a controller will render a html page. But you can easily make it respond with .xml or .json or .csv if you write a web api for it

Erb is a library class that generates text. Nothing more. It expects a file that contains static text and ruby code mixed. It will run the ruby code and write the result to another file which in case for your controllers is html

Solution 6 - Ruby on-Rails

ERB is templating Class in Ruby and is often used in .rhtml or .erb.html (HTML with embedded Ruby) in rails.

Here is a nice detail on the Ruby docs.

http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkhanhView Question on Stackoverflow
Solution 1 - Ruby on-RailsChowlettView Answer on Stackoverflow
Solution 2 - Ruby on-RailsNimesh NikumView Answer on Stackoverflow
Solution 3 - Ruby on-RailsMark AmeryView Answer on Stackoverflow
Solution 4 - Ruby on-RailsAndy YoungView Answer on Stackoverflow
Solution 5 - Ruby on-RailsAhmed AliView Answer on Stackoverflow
Solution 6 - Ruby on-RailshindenbugView Answer on Stackoverflow