Tutorials Point

  Learning Ruby on Rails 2.1
  Advanced Ruby on Rails 2.1
  Ruby on Rails Quick Guide
  Ruby Tutorial
  Ruby on Rails Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Ruby on Rails 2.1 and HTML - RHTML

previous next AddThis Social Bookmark Button


RHTML is HTML mixed with Ruby, using HTML tags. All of Ruby is available for programming alongwith HTML:

Following is the syntax of using Ruby with HTML:

<% %>   # executes the Ruby code as a block
<%= %>  # executes the Ruby code and displays the result


<% @products.each do |p| %>
  <li><%=  @p.name %></li>
<% end %>

The output of anything in <%= %> tags is directly copied to the HTML output stream. To secure against HTML injection, use the h() function to html_escape the output

For example::

<%=h @user_entered_notes %>

previous next Printer Friendly