MikeJX MikeJX - 1 year ago 69
Ruby Question

How can I include Ruby code in my HTML file?

I am new to programming and recently I started learning HTML, CSS and JavaScript and I would like to know how to include Ruby code in our HTML file as we do for example with PHP.

Is there a specific way to put Ruby code in HTML or I can do it like we do with PHP?

Answer Source

You could use Ruby on Rails, a framework written in Ruby. If you are new to Ruby you could check out this article to get started with Rails and learn how to install it and create your first app.

Also, you can learn more about Ruby on Rails on its Wikipedia page here.

In order to use it, just like you would in PHP change the file.html file, but in this case to file.erb not file.php.

The syntax is as follows:

<h1><%= "I'm learning Ruby on Rails" %></h1>

Then you have to run it:

ruby -rerb -e 'puts ERB.new(File.read("file.erb")).result'