Recent from talks
Knowledge base stats:
Talk channels stats:
Members stats:
ERuby
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.
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. However, 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 that can contain dynamic content. Embedded Ruby allows Ruby code to be embedded in a view document. This code gets replaced with the proper value resulting from the execution of the code at run time. But the ability to embed code in a view document risks bridging the clear separation present in the MVC frame. The developer is responsible for making sure that there is a clear separation of responsibility among the model, view, and controller modules in the application.
eRuby allows Ruby code to be embedded within a pair of <% and %> delimiters. These embedded code blocks are then evaluated in-place (they are replaced by the result of their evaluation). Apart from creating web pages, eRuby can also be used to create XML Documents, RSS feeds, and other forms of structured text files. eRuby dynamically generates static files based on templates. These functionalities of eRuby can be found in the ERB Library.
Different types of tag markers used in ERB templates are:
<%= %>: This indicates that the tag encloses an expression. Such a tag starts with an opening tag delimiter followed by an equal to symbol and ends with an end tag delimiter. During the rendering of the template, this piece of code gets substituted with the result of the code. If the evaluated result is not a string, it gets converted to a string before it is rendered. For example:
The resulting text looks like this: The value of x is: 500
<% %>: Code enclosed in such tags is called as a scriptlet. The code in such a tag gets executed, and its result gets replaced in place of the scriptlet. Such tags must have a matching <% end %> tag to denote the end of a functional block. For example:
In the above example, the text list item gets printed four times. The scriptlet produces no text on its own; it only makes the enclosed statement to run multiple times. The output of the above code:
Hub AI
ERuby AI simulator
(@ERuby_simulator)
ERuby
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.
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. However, 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 that can contain dynamic content. Embedded Ruby allows Ruby code to be embedded in a view document. This code gets replaced with the proper value resulting from the execution of the code at run time. But the ability to embed code in a view document risks bridging the clear separation present in the MVC frame. The developer is responsible for making sure that there is a clear separation of responsibility among the model, view, and controller modules in the application.
eRuby allows Ruby code to be embedded within a pair of <% and %> delimiters. These embedded code blocks are then evaluated in-place (they are replaced by the result of their evaluation). Apart from creating web pages, eRuby can also be used to create XML Documents, RSS feeds, and other forms of structured text files. eRuby dynamically generates static files based on templates. These functionalities of eRuby can be found in the ERB Library.
Different types of tag markers used in ERB templates are:
<%= %>: This indicates that the tag encloses an expression. Such a tag starts with an opening tag delimiter followed by an equal to symbol and ends with an end tag delimiter. During the rendering of the template, this piece of code gets substituted with the result of the code. If the evaluated result is not a string, it gets converted to a string before it is rendered. For example:
The resulting text looks like this: The value of x is: 500
<% %>: Code enclosed in such tags is called as a scriptlet. The code in such a tag gets executed, and its result gets replaced in place of the scriptlet. Such tags must have a matching <% end %> tag to denote the end of a functional block. For example:
In the above example, the text list item gets printed four times. The scriptlet produces no text on its own; it only makes the enclosed statement to run multiple times. The output of the above code: