Home arrow Ruby-on-Rails arrow Page 2 - Testing a Book Emporium Application

Testing a Book Emporium Application

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).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
April 30, 2010
  1. · Testing a Book Emporium Application
  2. · Starting Emporium for the First Time
  3. · How Does Ruby on Rails Work?
  4. · Modifying the Generated View
  5. · Creating the Layout
  6. · Creating a Style Sheet

print this article

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
=> 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

WEBrick is now running and configured to handle incoming requests on port 3000. Static content—like images, style sheets, and JavaScript files—are served by WEBrick from thepublicdirectory located under the application root directory. Requests for dynamic content are dispatched to and handled by Ruby on Rails.

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:

$ rm /home/george/projects/emporium/public/index.html

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.

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials