Lab 0: get RoR installed and running

From RAD Lab

Revision as of 01:55, 31 January 2008; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

Note: This lab has THREE parts. Be sure you do all three:

  1. Get RoR and Hello World running on your platform (one-click installers are provided for Mac OS X and Windows)
  2. Choose and install (if necessary) a source code editor
  3. Install the Subversion client on your platform (one-click installer for Mac and Windows)

Contents

Get RoR and Hello World running on Mac OS X (10.4.x and lower)

Note : Leopard should have everything you need to run Ruby on Rails out of the box.

thanks to Arthur Klepchukov for these instructions

  1. Download the latest Locomotive package (http://locomotive.raaum.org/). Mount the installer and drag the main folder to your Applications folder. You’ve just installed SQLite and an easy way to manage your Rails projects.
  2. Open Locomotive and create a new project. Don’t create a new directory for your project; Locomotive will handle that for you. Note the pathname of the directory created; we'll refer to it as $PROJ.
  3. From Locomotive, choose Applications > Open Terminal. This will open a terminal (shell) with the environment variables set correctly. Important. If you just open a regular Terminal rather than opening it from within Locomotive, stuff won't work.
  4. Now we'll create a database for our new project. In the Terminal, cd to $PROJ and type sqlite3 hello_world_dev.db. This will create a new SQLite database called hello_world in the project directory, and then drop you into the sqlite command-line tool.
  5. Generate a scaffold for stories: still in $PROJ, run ruby script/generate scaffold story name:string author:string content:text
  6. Open $PROJ/config/database.yml. In the "development:" section, change adapter to sqlite3 and database to $PROJ/hello_world_dev.db, and comment out the other lines by preceding them with a pound sign (#).
  7. From your main project directory $PROJ, run rake db:migrate. This will read the database schema implied by the migration created by the scaffold (db/migrate/001_create_stories.db) and create table(s) in hello_world_dev.db to match.
  8. In Locomotive, select your newly created project and Run it. Note the port number (You can change it in Info).
  9. Visit http://localhost:number/ where number is the port number. You should see "Welcome aboard." Also try appending /story/ to the URL. You should see an empty list of stories with a link to make a new story. Congratulations, you’re on Rails and SQLite!

Getting RoR and Hello World running on WinXP/Win2K/Vista

Thanks to Alex Bain for these instructions


  1. For Win32, we recommend the Instant Rails installer, which installs Ruby, Rails, a Web server, and MySQL in a self-contained way that doesn't modify the rest of your system. As the FAQ explains, your spyware filter may incorrectly report that this package contains spyware, but it really doesn't. Note that you need to do the install as Administrator.
    • Note: we haven't tested it ourselves, but we have reason to believe that this InstantRails-based process should work with Vista too.
  1. This part's a bit weird. The built in Windows unzip functionality may not properly unzip this file because some files in the zip archive have path names longer than 260 characters, causing Windows to choke. To get around this, download, install and use the free and open source 7-Zip to unzip the file to the directory where you plan to keep your Rails projects. A suggestion would be something like: C:\htdocs\InstantRails.
  2. Go to C:\htdocs\InstantRails (or your chosen directory) and run InstantRails.exe. It will prompt you about resetting some configuration files, so hit OK to continue.
  3. Now we'll create our Hello World app. First, click the 'I' icon next to the Apache button, select 'Rails Applications', and 'Manage Applications'. This will pop up a dialog that lets you create a new application in C:\htdocs\InstantRails\rails_app (or wherever you installed InstantRails) or start up an existing application.
  4. Click 'Create a New Rails App...', which will open a Terminal window. In that window, type rails HelloWorld.
  5. Next we have to create a database for our app. InstantRails installs the MySQL database by default, so we'll create the database there using the MySQL command-line interface. (You can also download MySQL GUI Tools Bundle.)Enter these commands, (without the comments - those are for your benefit):
mysql --user=root		## Connects to the local mysql server installed with Instant Rails
show databases;			## Shows a list of the current databases.
create database helloworld_development;	## Create our databases.
show databases;			## helloworld_development should be there.
quit;				## Done here.
  1. Now that we have an application skeleton and a database for it to use, we'll create a trivial controller and model as well as populate our database with a table corresponding to that model. Follow steps 5-6-7 in the Mac OS X instructions above to create those files. Make sure to type those commands from the shell (DOS) and make sure your database adapter is mysql in config/database.yml.
  2. Time to run the app! In the Instant Rails dialog box click 'Refresh List' to see our new HelloWorld application show up. Click on the app name and click 'Start with Mongrel'
  3. The terminal window will have a line that says: 'Mongrel available at 0.0.0.0:XXXX'. Whatever that port number is should be the one you use. It will most likely be 3000, but may be 3001. Open a browser and navigate to http://localhost:3000/ (or whatever that port was) and you should see a welcome screen. If you add /story/ to the URL you should be able to interact with the scaffolded Story views.

Congratulations, you're on Rails!

Pick an Editor

You'll be editing lots of text files, so don't even think about using Word.

  • If you already use Emacs or vi, great. Mac OS X includes both of these and you can run them from the Terminal's (i.e. bash) command line. Note that these are text-only and just run in an ANSI terminal window. *You can get a GUIfied version of Emacs for Mac OS X or Windows. The latest Emacs release (Emacs 22) has built-in support for Ruby and HTML 2-mode (HTML with embedded Ruby).
  • The Rails core team and many others use TextMate (Mac OS X only), which has extensive support for syntax highlighting etc. The RAD Lab has subsidized a UC Berkeley site license for this software; you will need your CalNet ID and passphrase to download it from UCB Software Central.

Install Subversion

You'll be using Subversion for source/configuration management. It's freeware.

The main project page is http://subversion.tigris.org.