Agile Web Development with Rails

Start from the beginning
                                        

CREATING A NEW APPLICATION

create log/development.log

create log/test.log

work>

The commandhas createdadirectory named demo.Popdowninto thatdirec-tory, andlistits contents(using ls on a Unix box or dir under Windows). You should seeabunch of .lesand subdirectories.

work> cd demo

demo> ls -p

README components/ doc/ public/ tmp/

Rakefile config/ lib/ script/ vendor/

app/ db/ log/ test/

Allthesedirectories(andthe .lesthey contain) canbeintimidatingtostart with,but we canignore most of them when we start.In this chapter, we�fll use only two of themdirectly: the app directory, where we�fll write our application, and the script directory, which contains some useful utility scripts.

Let�fs start in the script subdirectory. One of the scripts it contains is called server.This script starts a stand-alone web server that can run our newly cre-atedRails application underWEBrick.1 So, withoutfurther ado,let�fs startour demo application.

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-01-08 21:44:10] INFO WEBrick 1.3.1

[2006-01-08 21:44:10] INFO ruby 1.8.2 (2004-12-30) [powerpc-darwin8.2.0]

[2006-01-08 21:44:11] INFO WEBrick::HTTPServer#start: pid=10138 port=3000

Asthelastline ofthe start-uptracingindicates, wejuststarted a web server on port 3000.2 We can access the application by pointing a browser at the URL http://localhost:3000. The result is shown in Figure 4.1 (although the version numbersyou see willbedifferent).

Ifyoulook at the window whereyou startedWEBrick,you�fll see tracing show-ing you accessing the application. We�fre going to leave WEBrick running in this console window. Later on, as we write application code and run it via our browser, we�fll be able to use this console window to trace the incoming requests.Whenthetimecomesto shutdownyourapplication,youcanpress

1. WEBrick is a pure-Ruby web server that is distributed with Ruby 1.8.1 and later. Because it is guaranteed to be available, Rails uses it as its development web server. However, if web servers called Mongrel or Lighttpd are installed on your system (and Rails can .nd one of them), the script/server command will use one of them in preference to WEBrick. You can force Rails to use WEBrickbyproviding an option to the command.

demo>ruby script/server webrick

2. The0.0.0.0 partofthe address means thatWEBrick will accept connections on allinterfaces.On Dave�fs OSX system, that means bothlocalinterfaces(127.0.0.1 and ::1) andhisLAN connection.

Report erratum

Prepared exclusively for Jordan A. Fowler

HELLO, RAILS!

Figure4.1:NewlyCreatedRailsApplication

control-Cinthis windowto stopWEBrick.(Don�ftdothatyet.we�fllbe using thisparticular applicationin a minute.)

Atthispoint, wehave anew applicationrunning,butithas none of our code init.Let�fs rectify this situation.

4.2 Hello, Rails!

You've reached the end of published parts.

⏰ Last updated: Mar 22, 2008 ⏰

Add this story to your Library to get notified about new parts!

Agile Web Development with RailsWhere stories live. Discover now