Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Ruby code in HTML?

Tags:

ruby

In PHP, it is possible to do this:

<input type="text" value=" <?php echo "Hello world"; ?> ">

Is it possible to embed Ruby in HTML like that with or without Rails?

like image 629
nukl Avatar asked Aug 15 '10 08:08

nukl


People also ask

How to embed Ruby code in HTML?

Save the file as . html. erb to use embedded ruby codes with <%= ruby_code %> in html message.

Can you use Ruby in HTML?

So far we've looked at using Ruby to create HTML output, but we can turn the problem inside out; we can actually embed Ruby in an HTML document. There are a number of packages that allow you to embed Ruby statements in some other sort of a document, especially in an HTML page.

What does embedded Ruby process?

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.

What is embedded Ruby interpreter?

eRuby stands for embedded Ruby. It's a tool that embeds fragments of Ruby code in other files such as HTML files similar to ASP, JSP and PHP. eRuby allows Ruby code to be embedded within (delimited by) a pair of <% and %> delimiters.


3 Answers

You will need to use a templating engine like Ruby Templates (ERB). Here's an example. Rails uses ERB so you could easily do this in each of your templates.

like image 72
Darin Dimitrov Avatar answered Oct 16 '22 10:10

Darin Dimitrov


Rails has something called ERB to do just this sort of thing.

like image 1
Manoj Govindan Avatar answered Oct 16 '22 09:10

Manoj Govindan


Use HAML for HTML templating, otherwise ERB.

like image 1
Reactormonk Avatar answered Oct 16 '22 10:10

Reactormonk