

Click on Next, then
specify project details, including name: demo

This will both generate a Rails skeleton for the app and create a WEBrick server! Click on Finish…
We now have the complete default rails application created in the Eclipse IDE default workspace:

Notice the complete rails app tree on the left, and below the WEBrick server created for this project (a previous project, Depot, has already occupied port 3000, so this one gets 3001 assigned to it).
Start the webserver for this project by selecting the appropriate server and clicking on the green “advance/play” icon:

and verify that it is running (“stopped” => “started”)

We can now point our browser at localhost, specifying the port assigned to the current project’s WEBrick: http://localhost:3001:

As explained in the book, Rails accepts requests from a browser, “decodes the request to find a controller, and calls an action method in that controller. The controller then invokes a particular view to display the results back to the user.”
Now, to write a simple “Hello, world” application, we don’t actually need a model at all; we simply need to code a controller and a view. For example, a controller say with a method hello and a matching view hello. Let’s see how that pans out.
If we were running rails from the command line, we would have rails magically generates the controller with the command:
ruby script/generate controller Say
but here in Rad Rails, we simply go to the Rails Generator View, specify the name “Say” and hit the “Go” button on the right:

after which we see the following:

Now that the Say controller has been generated, we can “Say” something. Following the AWDWR book, what we want to do first in the demo app is to “Say hello”, and that would be invoked by the browser being pointed at:
http://localhost:3001/say/hello
and, here is the fun MVC (model-view-controller) part: the “Say” controller must have an action (method) “hello”! When the http server sees ”/say/hello”, it invokes the app with the Path Info ”/say/hello”.
Rails then knows to create an instance of the the class SayController and to invoke its action (method) hello(). It will then hand the result to a display (view) and the MVC chain is complete, and we will have a display in the browser.
So we need to edit the controller Say and give it some action! In Rad Rails this is really simple; in the tree on the left we navigate to the file /demo/app/controllers/say_controller.rb which we have just generated and double click on the file node. We see it contains the default
class SayController < ApplicationController end
and then add in the action hello as follows; I type “def” and then hit <Ctrl Space>; a list of options pops up and I hit

The method is empty, but what that really means is that we are not overriding, that is, we inherit all of, the functionality of the parent ApplicationController class. Save your work.
At this point, if we go ahead and invoke the hello method with the browser what we have done so far will work, and we will get an error message “template missing”, which is logical considering that we have not specified a view for Rails to display.
So to create the view, we navigate to /app/views/say folder, right click on it, and choose /New/File. We are presented with a dialog with the /app/views/say folder selected; just type in
hello.rhtml
<html>
<head>
<title>Hello, Rails!</title>
</head>
<body>
<h1>Hello from Rails!</h1>
</body>
</html>

Save your work and point your browser to: http://localhost:3000/say/hello and you should see what follows:

(Note that I use port 3001, since I have another Rad Rails project open which is already using the 3000 port, but use the port specified by Rad Rails when you created the project; if this is your only project open it will be port 3000 and http://localhost:3000/say/hello should work fine.
OK, we’re hooked up on MVC!
Victor Kane (ProjectMaster) and awebfactory.com.ar