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.

Hello World

Hello World!

<%= 'Hello Dynamic World' %>

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!

Browny L. wrote:

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

Hello World

Hello World!

<%= 'Hello Dynamic World' %>

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!

What does your generated HTML look like? What’s in your application
log?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

Browny L. 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.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:
Marnen Laibow-Koser wrote:
  
Browny L. 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.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

.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?

Norm

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

2009/10/6 Browny L. [email protected]:

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.

Colin

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?

Many many thanks again

Marnen Laibow-Koser wrote:

Marnen Laibow-Koser wrote:

Browny L. 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.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

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 <%= %>
works!

Many thanks again

Colin L. wrote:

2009/10/6 Browny L. [email protected]:

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.

Colin

Hello, Marnen Laibow-Koser

I run C:\Documents and Settings\brownylin\rails\my_app>rake routes

and the results are shown below three lines:

(in C:/Documents and Settings/brownylin/rails/my_app)
/:controller/:action/:id
/:controller/:action/:id(.:format)

What does the routing problem mean? And what dose the three line output
means?

Many many thanks for Marnen Laibow-Koser ^^

Marnen Laibow-Koser wrote:

Browny L. 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 <%= %>
works!

Then you have a routing problem. What’s the output if you type “rake
routes” at the command line?

Many thanks again

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Browny L. wrote:

Hello, Marnen Laibow-Koser

I run C:\Documents and Settings\brownylin\rails\my_app>rake routes

and the results are shown below three lines:

(in C:/Documents and Settings/brownylin/rails/my_app)
/:controller/:action/:id
/:controller/:action/:id(.:format)

OK, then that’s just the defaults. I’m not sure you’d be able to get
say/hello to work with just these routes. I assume you have an action
called hello in your SaysController class?

What does the routing problem mean? And what dose the three line output
means?

http://guides.rails.info/routing.html

Many many thanks for Marnen Laibow-Koser ^^

You’re welcome!

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Browny L. 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 <%= %>
works!

Then you have a routing problem. What’s the output if you type “rake
routes” at the command line?

Many thanks again

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs