Lowongan Kerja

Galleri Foto Artis

Gallery Tattos

13.2. Installation
This entire preamble leads to the two important questions of where to get Ruby and where to get Rails. That's easy. A simple Google search for "ruby rails" is enough to answer both questions simultaneously. I do recommend a single search instead of individual searches, unless, of course, you are also interested in jewelry and traveling by train.

The process of installing Ruby is dependent upon which operating system your machine is running. For wimps like me who happen to be running Windows XP Professional, listening to Jethro Tull, and writing a book, installation is simply a matter of downloading an .exe and double-clicking it to get the ball rolling. It installs just like the shrink-wrapped software that you purchase, minus the autorun CD and price tag, as Figures 13-1 and 13-2 show.
If the lack of an autorun CD makes you nervous, then, by all means, create your own autorun CD. However, if the lack of a price tag makes you nervous, I recommend that you buy a second copy of this book and give it to a friend as a gift. In this manner, you've got a bill and you've also given the nice people at Prentice Hall a reason to send me a check. In short, everyone is happy all around.

In a Windows environment, the installation of Ruby on Rails requires a couple additional steps. The first of these steps is to install Rails itself. If you have an Internet connection, this is just a single line; it is at the command prompt, but, nevertheless, it is a single line (see Figure 13-3).
However, if you are a real web developer and not a quiche-eating Windows user, installation will be a little more complex. Don't worry, it isn't a "Windows is superior" thingin fact, it is more of a "Windows has training wheels" thing. Now that I've thoroughly confused you, the fact is that the RubyGems package manager is part of the Windows installer, which isn't the case with Linux. However, because Linux isn't a stagnant environment, I recommend checking the Ruby website for the latest installation procedures.

Now that you've (hopefully), installed Ruby and Rails, it is time to kick the steel wheels (ouch) and take it out for a little spin. Woo-hoo!



13.3. A Little Ruby on Rails Warm-Up
As stated previously, Ruby is the object-oriented programming language, and Rails is the framework used to develop applications. Let's say, for example, that I want to create a mad scientist application using Ruby on Rails. The steps would be something like the following:
1. If it doesn't exist, create a folder/directory to hold each of my Ruby on Rails applications. In this example, I created a folder called rails on my C: drive.
2. Using the command prompt, enter cd rails. This changes the current directory to C:\rails.
3. Create an empty web application by running the command rails madscientist, as shown in Figure 13-4.
4. Start the web server WEBrick, which is included with Ruby, as shown in Figure 13-5.
5. Check out what is out on the web server in the browser of your choice (see Figure 13-6).
6. Now is a good time to type Ctrl+C in the command prompt window to shut down WEBrick, as shown in Figure 13-7, before falling back and regrouping. Well, we're only partway there; in fact, we should consider ourselves lucky that there is anything at all to show. Satisfied? Neither am I, so to progress further, we need to understand where things go in a Rails application.

The rails madscientist command created a number of folders and files that perform various functions. Take, for example, the database.yml file in the config folder; its purpose is to provide the application with details regarding the database to be used by the application. This is an example of the Rails "place for everything and everything in its place" approach. Personally, I wish this idea was more widespread. It would have gotten me out of some embarrassing moments in the past.

Another folder that is of interest is the public folder. Along with its three child folders, images, javascripts, and stylesheets, it provides a standard location for stashing the aforementioned. In most other environments, locating these types of files is more akin to a treasure hunt than web development.

The final folders that I'll cover are the app folder, along with the child folders called: controllers, helpers, models, and views. Still feel like you're in the dark? Give me a moment to illuminate. The first directory, controllers, contains classes that handle web requests from the visitor. The helpers directory holds helper classes, which are used by other classes, such as controller classes. Model classes, contained in the models subdirectory, are used to wrap the data stored in a database. Personally, I think that this is where application development can get really messy and often goes wrong. Finally, there is the views subdirectory, which holds the views. Views are the templates that are converted to HTML and returned to the visitor's web browsers.

Although at first glance it might seem that the application is spread around a bit, that really isn't the case. Instead of the normal "I know it is around here somewhere" approach usually associated with web development, Rails provides a consistent location for each class. If only this approach could be applied to the real world, I would spend a lot less time looking for my watch.


Related Posts



0 comments:

Post a Comment

 

Networking

FOREX TRADER

Sexi Women

Copyright © Free ebooks Download | Powered by Blogger | Template by Blog Go Blog