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?
Save the file as . html. erb to use embedded ruby codes with <%= ruby_code %> in html message.
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.
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.
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.
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.
Rails has something called ERB to do just this sort of thing.
Use HAML for HTML templating, otherwise ERB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With