Browser can't display the ruby part in rhtml

I create a simple .rhtml file "hello.rhtml" in the "view" folder of the
rails app.

     <title>Hello World</title>
     <p>Hello World!</p>
     <p><%= 'Hello Dynamic World' %></p>

The problem is when I run the web server and load the url
"http://localhost:3000/say/hello", only "Hello World!" is shown, the
second line 'Hello Dynamic World' is gone?

Anyone can help me? Thanks very very very much!

Marnen Laibow-Koser wrote:

Marnen Laibow-Koser wrote:
Browny Lin wrote:
I create a simple .rhtml file "hello.rhtml" in the "view" folder of the
rails app.

Ack! Didn't notice this when posting the first time around...if you're using Rails 2.x, that should be hello.html.erb . If your tutorial is using the .rhtml extension, then it's out of date and you should follow another tutorial.
Marnen Laibow-Koser

.rhtml works
fine at least through 2.2.2. .html.erb may be the way to go but .rhtml
is not the problem. The problem is what do you expect a string to do?
<%= %> says to evaluate the ruby expression and then return the
result. I think the code should be something like <%= p ‘whatever’

Am I loosing my mind?


Thanks for your information, Marnen Laibow-Koser

My rails is 2.3.4, I change the file "hello.rhtml" to "hello.html.erb"

But the browser still just show the first line, and doesn't show
anything inside <%= XXX %>, do I miss something?

Make sure you have not got any other files hello.* in the view folder
(backup files for example). Some versions of Rails have been confused
by these. Temporarily remove hello.html.erb and make sure that it
then complains it cannot find the file. This will make sure it is
picking up the right one.

What does the generated html look like (View, Page Source or similar
in browser)? Post the relevant section here.


Browny Lin wrote:

It works !!! Thanks very very much for Colin ^^

I temporarily remove hello.html.erb and the browser show the error
message "Missing template say/hello.erb in view path app/views"

So I change file name to hello.erb, and the ruby code inside <%= %>

Then you have a routing problem. What's the output if you type "rake
routes" at the command line?

Many thanks again