In this conclusion to a three-part series on how to do a project setup and proof of concept for a fictional bookstore on Ruby-on-Rails, we'll actually start the application for the first time and see how it functions. This article is excerpted from chapter one of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Testing a Book Emporium Application - Starting Emporium for the First Time (Page 2 of 6 )
We are now ready to start up Ruby on Rails and Emporium for the first time, so we tell George to come over and have a look. We don’t have to install any separate web servers, like Apache or LightTPD, while developing and testing Emporium. We can use the Ruby on Rails script/servercommand, which starts an instance of the WEBrick web server.
Note WEBrick is a Ruby library that allows you to start up a web server with only a few lines of code. WEBrick is suited only for development and testing, not production. In Chapter 12, we will show you how to set up and deploy the Emporium project to the LightTPD web server.
Next, executescript/serverin the Emporium application directory to start WEBrick.
$ cd /home/george/projects/emporium $ 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-03-19 03:30:50] INFO WEBrick 1.3.1 [2006-03-19 03:30:50] INFO ruby 1.8.4 (2005-12-24) [i686-linux] [2006-03-19 03:30:50] INFO WEBrick::HTTPServer#start: pid=14732 port=3000 --------------------------------------------
Openhttp://localhost:3000in your browser to see the Emporium application in all its glory. You should see the default Welcome page shown in Figure 1-1. The most interesting thing on the page is the “About your application’s environment” link, which, when clicked, takes you to a page that shows you some technical information about your application.
Tip You can start WEBrick and your application in different environments by using the environment parameter:script/server -e test. For example, the following will start your application’s test environment and WEBrick in daemon mode, listening on port 80:script/server -d -p 80 -e test
Figure 1-1. The default Ruby on Rails Welcome page
The code you see on the Welcome page is in theindex.htmlfile, which is located in thepublicdirectory under the application root. It was created by therailscommand and should be deleted, so that it doesn’t prevent the controller for the root context from being called:
You will get an error,Recognition failed for "/", if you accesshttp://localhost:3000again after deletingindex.html. The error is thrown because there are no controller and action set up to handle the request.
We are now ready to start writing some code. But first, we’ll introduce you to how requests are handled by the Rails framework.