Thursday, December 21, 2006

Steps in Creating a Rails Application

For those new to Rails, here is a proposed sequence of steps to follow in order to make a Ruby on Rails application:

  1. Use the rails command to generate a skeleton for your web application.
  2. Create a database and its tables using MySQL. Make sure to follow Rails conventions in naming tables and table columns.
  3. Use the scaffold generator to automatically create each model and its controller and views.
  4. Manually code relationships between tables into model files.

You can now go ahead and view your web application in the browser after starting the web server.

You can start shaping up your web application from here. Go back to the controllers and views, make needed modifications then go back and view your application in the browser. Keep modifying the application files till your web application is complete and is shaped like what you have in mind.

The above sequence is merely a proposed sequence. It is specially suitable for new comers to Ruby on Rails. Sure there are alternative paths. For instance, one can start by creating an empty database, and use Ruby on Rails migrations to create the tables. One can also go about writing controllers and views by hand without first using the scaffolding features of Rails.

If you would like to use migrations rather than creating the database tables directly with MySQL, then you can follow this alternative approach:

  1. Command line prompt, rails_apps folder: rails appname
  2. MySQL command line console: create database appname_development;
  3. Generate a migration after going to the appname folder: ruby script/generate migration add_tables
  4. Edit 001_add_tables.rb file to define database tables.
  5. rake migrate
  6. For each model (~table): ruby script/generate ModelName
  7. Define relationships between database tables inside model files (appname/app/models/ModelName)
  8. ruby script/server
  9. Open your browser at:'s'

No comments: