Use it with Rails and find out how to create your web applications
Ruby is a language that has been around for years, but is getting a lot of exposure now thanks to the web application framework called Rails, along with an increasing appreciation of dynamic languages.
Since both Ruby and Rails (see previous column) are free, there’s no harm investigating whether Ruby might suit you. To get started on Windows, go to rubyforge.org and download the One-Click Ruby Installer for Ruby 1.8.4 or higher.
This is a Windows installer that loads Ruby along with several essential add-ons, including the Rubygems packaging system. You can then use Rubygems to install Rails. Open up a command prompt, switch to the Ruby directory, and enter:
gem install rails –include dependencies
You have to be connected to the Internet for this to work. Another thing to check if you experience problems is the system path, which should include the ruby.exe executable. All going well, gem will go and fetch the latest Rails, currently version 1.1. You can test Rails like this:
rails c:\rails\pcwapp
This command creates a skeleton Rails application at the specified location. Switch to the pcwapp directory and type:
ruby script/server
This starts the Rails application, usually on port 3000. You can then browse to http://localhost:3000. All being well, you will see the Rails welcome page, in which case both Ruby and Rails are installed successfully.
Getting content into Rails
When you create a Rails application, files and folders appear in the
specified location. By adding very little code, you can make your application
spring into life. First, a word of explanation.
Two key tenets of the Rails philosophy are ‘don’t repeat yourself’ (DRY) and ‘convention over configuration’. An example of this principle is the close relationship between classes, methods and the pages in your application.
To see how this works, open a command prompt, switch to the root directory of pcwapp, and type:
ruby script/generate Welcome
This creates several files, including Welcome_Controller.rb in the app\controllers directory. Edit this file and add a method called index. The code looks like this:
class WelcomeController < ApplicationController
def index
end
end
You have just defined a virtual path in your web application called Welcome, within which there is a page called index.
In other words, the URLs in your application map to the Controller classes and methods. Index is also the default page, so if you navigate to http://localhost:3000/welcome, you will get an error message telling you the template index.rhtml is missing.
Related articles
Q.How do I store musician and other information about...
Q.Why can't my browser find the website address I typed...
Q.All updates have been downloaded, so why won't Windows...
Communications provider says companies that establish careful flexible working patterns reap the benefits, but most companies have no plans for flexible working
Voice over IP. The routing of voice conversations over the internet, which is cheaper than the telephone...
|
|
|
|
|
Nikon Coolpix S570 BlackPrice: £66.99 |
Computeractive Ultimate Guide - Storage, Sharing & BackupPrice: £5.99 |
Back Issue CD-Rom 13 (2010)Price: £9.99 |
Hallmark Card Studio DeluxePrice: £15.31 |
Marine AquariumPrice: £15.41 |