Creating a New Rails Application

btn_watchdemo20070807

So far I’ve been sticking to working with Rails applications that are already set up. Track Magic, however, can also help you set up your new Rails applications. Track Magic takes care of all of the details for you, leaving you free to concentrate on your application and table design. To show you how it works I’ll create a new Rails application for a charitable foundation.

I’m going to create my new Rails application using MySQL, which is already set up and running on my computer. By default new Rails applications are created using SQLite, but I can easily change that with the Track Magic Preferences dialog (in the Track menu). I’ve already set up a list of available Rails hosts (see Managing Hosts), so all I need to do is choose the host I want to use from the pop-up menu. While I’ve got the dialog open I also check the When creating a new Rails table, auto create synchronized Panorama database? option.

001_Preferences

To create the new application I select Create New Rails App from the Track menu. (I could also simply click the + button in the upper right).

001_CreateMenuAndButton

Track Magic asks me for the location and name of the new application, which I’ll call foundation.

002_CreatingAppDialog

When I press the Save button Track Magic creates the application itself. After a short delay it displays the shell output from this creation process:

003_CreateAppShellResult

Since I specified a MySQL host, Track Magic now prompts me to verify the host connection information, as well as the database name.

004_ConfigHost

The information is all fine, so I press OK. Now Track Magic asks if I want it to create the MySQL databases for me. Since I’m using the MySQL server on my own machine I go ahead and let Track Magic create the databases. (If I was using a MySQL server administered by someone else, I might need them to create the databases for me.)

005_ConfirmCreateMySQL

Ok, the app is ready to go, and is now listed at the top of the Track Magic window.

006_TrackMagicWithNewApp

Of course the new app is empty. The next step is to add a table of donors. I can either choose Create New Rails Table from the Application menu, or click on the + button above the list of tables.

001_CreateTableMenuAndButton

Track Magic opens the Create New Table dialog, which allows me to set up the fields in the new table. I simply enter each field name and press Return to add it to the list. For this table all of the fields are strings, but if I need other types I can simply click on string to select from a pop-up menu of field types (see Creating a New Table for more information.)

007a_NewTableDialog

After entering the field names I enter the name for the new table. This name should be singular, since Rails will pluralize the name. For example donor will become donors, contact will become contacts, or person will become people.

008_NewTableName

After a short delay Track Magic displays the shell output from the table creation process:

009_NewTableShellResult

Since I checked the When creating a new Rails table, auto create synchronized Panorama database? option in the Preferences dialog (see above), Track Magic will automatically create a local synchronized copy of the new table.

010_NewDataSheet

The new table is ready to use, and I can start entering data into it immediately.

011a_DataEntry

Once I’ve entered some data I can choose the Upload All Changes to Rails command to upload it to my new Rails table.

012_RailsMenuUploadChanges

012_DataEntry

When I created this new table a moment ago I forgot to include fields for each donor’s telephone number and e-mail address. What was I thinking? To fix this, I choose the Add/Remove Fields from the Application menu. The dialog that appears is very similar to the dialog for creating a new table. I add three new fields: email, phone and notes.

013_AddFields

When I’m done the Track Magic window show the three new fields:

014a_TrackMagicWithNewFields

I’ve added the three new fields to the Rails table, but they aren’t yet included in the local Panorama database associated with this table. To fix this I flip back to the data sheet (I click on the Panorama "cube" icon in the Track Magic window if the data sheet has been closed) and choose the Local Field Configuration… dialog in the Rails menu. This dialog lists all of the fields in the Rails table. I can enable and disable specific fields, and also drag to change the order of the fields (see Field Configuration for more information.)

015_FieldConfiguration

When I click the Update Configuration button the local Panorama database is restructured to match the dialog. Now I can view and edit the three new fields from my local Panorama database.

016_DataSheetWithNewFields

Importing a Text File

I’ve been given a tab delimited text file that has the names and contact information for previous donors to this foundation — volunteers were keeping the list in Excel and exported it to a text file for me. There is no need to re-type the data, since it can easily be imported into my new Rails table. I start by making sure the donors data sheet is the topmost window, then choose Import Text from the File menu. This opens the Text Import Wizard, seen below. Now I drag the text file (in this case donors2008.txt) and drop it onto the left side of the wizard.

017_DragToImportWizard

The left side of wizard shows the first line of data from the text file. The right side shows the fields in the Panorama database. My job is to match up the left and right sides by dragging data items from the left and dropping them on the corresponding field on the right.

019_ImportWizardDragFields

Here’s what the wizard looks like after I’ve matched up all of the imported data items with the corresponding database fields.

020_ImportWizard

Once the items are matched up I choose Import Data from the Import menu to actually bring the contents of the text file into the data sheet.

021_DataSheetWithData

I can review and modify (if necessary) the new data before I uploaded it to Rails. When everything is ready I choose Upload All Changes to Rails from the Rails menu.

012_RailsMenuUploadChanges

The Rails table is now populated with the imported data.

022_UploadDataNotification

In this example I created the Rails table first and then imported the data into it. You can also combine these into a single step, using the imported data as a template to set up the fields in a new Rails table. See Creating a New Table for more information on "cloning" a Panorama database or text file into a new Rails table.

Continue the Tour —> Rails Web Interface