RoR Hello From Rails App
From MashupCamp
Let's create our first Rails app.
[edit]
Creating An Empty Rails Application
Rails will create an empty application for us:
C:\>mkdir \rails
C:\>cd \rails
C:\rails>rails demo
create
create app/controllers
create app/helpers
create app/models
...
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
C:\rails>
This won't do anything, but sets up the files and directories we need.
[edit]
"Hello from Rails" Application
Now let's create a simple "Hello from Rails" application. Type:
C:\rails>cd \rails\demo
C:\rails\demo>ruby script\generate controller Say
exists app/controllers/
exists app/helpers/
create app/views/say
exists test/functional/
create app/controllers/say_controller.rb
create test/functional/say_controller_test.rb
create app/helpers/say_helper.rb
C:\rails\demo>
Now edit the app\controllers\say_controller.rb file to look like this:
class SayController < ApplicationController def hello end end
And create app\views\say\hello.rhtml:
<html>
<head>
<title>Hello Rails</title>
</head>
<body>
<h1>Hello from Rails!</h1>
</body>
</html>
Now start the Webrick server:
C:\rails\demo>ruby script\server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2006-07-11 21:13:31] INFO WEBrick 1.3.1 [2006-07-11 21:13:31] INFO ruby 1.8.4 (2005-12-24) [i386-mswin32] [2006-07-11 21:13:31] INFO WEBrick::HTTPServer#start: pid=2840 port=3000
And open your new Rails application:
http://localhost:3000/say/hello
Impressed? I am!
(This example taken from the fantastic Rails book [Agile Web Development with Rails]. Get a few copies so you can give some to your friends!)


