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.
rails helloworldcd helloworldruby script\generate controller helloworld- 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>
ruby script\server- Navigate to http://localhost:3000/helloworld in your browser and be greeted with your friendly application: "Hello World"