Ramaze by Example - Part 2: Base Application

November 18, 2008 at 13:36

Filed under: Computing — Pistos @ 13:36

This is part 2 of Ramaze by Example, a tutorial on web development. In Part 1: Database Schema, we setup the schema for our database.

The typical base Ramaze application consists of a Ruby script with the command Ramaze.start. Traditionally this file is called start.rb, but you could name it anything you like. Let’s examine the start.rb I’ve built (you can view the whole file on github or in your local repo clone).

require 'rubygems'
require 'ramaze'
require 'm4dbi'

Require some libraries. If your system is cool, you can omit “require 'rubygems'“.

$db = DBI.connect( 'DBI:Pg:todolist', 'todolist', '' )

Connect to the database. Pg is the DBI driver to use (for PostgreSQL), todolist is both the name of the database and the database user. The final argument is the database password. We don’t ever actually use the database handle ($db) in this tutorial, but if you should ever want to show off your SQL fu in one of your own apps, that’s what you would use. For our purposes, we only need to connect so that our ORM can access the database to do its thing.

acquire 'src/model/*'
acquire 'src/*'

Ramaze provides a nifty little command called acquire. This works like Ruby’s normal require command, except you can use wildcards and globs (* and **), like the Dir class supports.

Ramaze.start :port => 9001, :adapter => :mongrel

And finally, press the flipcovered red button to launch. Ramaze.start can take several configuration options. Here, we specify the TCP port to listen on, and which web server adapter to use.

Review

Let’s review what we’ve learned up to this point.

  • With Ramaze you write very little code.
  • You understand and know all the code of your app, because you wrote it.
  • acquire is like require, but allows wildcards.
  • Ramaze.start is the Ruby code that fires up your Ramaze application.

MVC - Model, View, Controller

In web development, there is a way of structuring your code, splitting it into three parts that are separate, yet which still work together. This architectural pattern is called “MVC”. MVC stands for Model, View, Controller. When working with Ramaze, you structure your application according to the MVC pattern.

The next three steps of the tutorial will cover each part of MVC. We’ll begin with the Model in Part 3: Model.

Share This

Related posts:

  1. Ramaze by Example - Part 3: Model
  2. Ramaze by Example - Part 5: Controller
  3. Ramaze by Example - Part 6: Adding Tasks
  4. Ramaze by Example - Part 4: View
  5. Ramaze by Example - Part 1: Database Schema

1 Comment »

  1. Pingback by Catholicism Computes » Ramaze by Example — November 26, 2008 @ 16:41

    [...] Part 2: Base Application [...]

RSS feed for comments on this post. TrackBack URI

Leave a comment

You may use Markdown syntax in your comment.

Powered by WP Hashcash

Powered by WordPress.
Close
E-mail It
Socialized through Gregarious 42