ERuby

eRuby
Other namesERB
Repositorygithub.com/ruby/erb
Written inRuby
TypeTemplate engine
LicenseBSD 2-Clause License

Embedded Ruby (also shortened as ERB) is a templating system that embeds Ruby into a text document. It is often used to embed Ruby code in an HTML document, similar to ASP and JSP, and PHP and other server-side scripting languages. The templating system of eRuby combines Ruby code and plain text to provide flow control and variable substitution, thus making the combined code easier to maintain.[1]

The View module of Ruby on Rails is responsible for displaying the response or output on a browser. In its simplest form, a view can be a piece of HTML code which has some static content. For most applications, just having static content may not be enough. Many Ruby on Rails applications will require dynamic content created by the controller (action method) to be displayed in their view. This is made possible by using Embedded Ruby to generate templates which can contain dynamic content. Embedded Ruby allows ruby code to be embedded in a view document. This code gets replaced with proper value resulted from the execution of the code at run time. But, by having the ability to embed code in a view document, we risk bridging the clear separation present in the MVC frame. It is thus the responsibility of the developer to make sure that there is a clear separation of responsibility among the model, view and controller modules of his/her application.[2]

  1. ^ Brown, Gregory (2009). Ruby Best Practices. O'Reilly. pp. 279–281. ISBN 978-0596523008.
  2. ^ Cite error: The named reference :2 was invoked but never defined (see the help page).