Forum: Ruby on Rails Displaying ruby content in rhtml

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Shrikant S. (Guest)
on 2009-01-03 02:02
Hi everyone,

I am a newbie to RoR. I installed the Instant Rails package 1.7, and
with scaffold, I was able to create and connect to a database.
However, when I embed some code in rhtml(list.rhtml in the tutorial
there), it does not display in browser. I can see the html part on the
screen without problem, but the ruby part does not get processed at all.
When I try a simple rhtml file such as below,

<title>All Recipes</title>
    <li>Addition: <% print "World!" %>    </li>
<h1>Online Cookbook - All Recipes</h1>

all I can see is
Online Cookbook.

I think this has something to do with eruby or erb, but do not know how
to proceed.

Any help would be much appreciated!

Frederick C. (Guest)
on 2009-01-03 02:09
(Received via mailing list)
On 3 Jan 2009, at 00:02, Shrikant Sv wrote:

<% puts ... %> or <% print ...%> achieves very little (at best it will
output to your server's log file).
You need to be using <%= which inserts the result of evaluating it's
contents, ie <%= %>

Ethan Gunderson (Guest)
on 2009-01-03 03:12
(Received via mailing list)

<% %> is code that is executed, but not displayed in the browser.
<%= %> is code that will be executed and displayed.

Hope that helps!

Ethan Gunderson

On Fri, Jan 2, 2009 at 6:02 PM, Shrikant Sv
Freddy A. (Guest)
on 2009-01-03 04:52
(Received via mailing list)
Just an example of both usages

<% if is_admin? do %>
  <h1><%= admin_title %></h1>
<% end %>
This topic is locked and can not be replied to.