Mix Ruby Code and HTML : ERB « Rails « Ruby






Mix Ruby Code and HTML


<html>
  <head>
    <title>Using Views</title>
  </head>
  <body>
    <h1>Working With Views</h1>
    This is an active view in a Ruby on Rails application.
    <br>
    <br>
    2 + 3 = <%= 2 + 3 %>
    <br>
    <br>
    Do loops work?
    <br>
    <% 3.times do %>
    Yes! <br>
    <% end %>
    <br>
    This page executes Ruby code on-the-fly.
  </body>
</html>



 








mixHTMLRuby.zip( 88 k)

Related examples in the same category

1.In Rails, embedded Ruby in .rhtml pages is run using a processor called ERb, for Embedded Ruby.
2.You can mix HTML and ERb as well
3.use puts to display text in a web page (It was printed out in the console.)
4.A loop executes the body of the loop
5.uses the Ruby Time.now method to display the current time
6.Escaping Sensitive Text