Monday, November 13, 2006

Rails: Hello World / HelloWorld

Note, I was developing on Windows at the time of this post.

Assuming that Ruby and Rails are already installed...
Go to the appropriate top level directory [where you want to create your new application]. For me, c:\develop\rubysrc.
  1. rails helloworld
  2. cd helloworld
  3. ruby script\generate controller helloworld
  4. You can either:
    • Use the controller DIRECTLY...
    class HelloController < ApplicationController
    def index
    render_text << EOF
    <html>
    <head>
    <title>Rails HelloWorld from Controller</title>
    </head>
    <body>
    HelloWorld from Controller
    </body>
    </html>
    EOF
    end
    end
    
    • Use a view... Create a file called index.rhtml in app/views/helloworld, containing "Hello World"
    <html>
    <head>
    <title>Rails HelloWorld from View</title>
    </head>
    <body>
    HelloWorld from View
    </body>
    </html>
    
  5. ruby script\server
  6. Navigate to http://localhost:3000/helloworld in your browser and be greeted with your friendly application: "Hello World"

2 comments:

Anonymous said...

Linux requires a forward slash:

ruby script/generate controller helloworld

Anonymous said...

i am not able to run this application on server.
it is showing "we are sorry something went wrong error".
what could be the problem?