Thanks to whoever fixed cgi.rb ( I think it was George ). I
was
planning to fix the dictionary/hash mismatch that was
causing
nitro/part/admin to fail on posts.
I'm now thinking about how to learn Nitro, and composing my
own
"outline" that could be expanded into a tutorial
as I go along. I have
the advantage of being a newbie -- and thus the perspective
that only a
newbie can have on how the learning progresses.
I thought I would capture that experience while I'm still
unfamiliar
with Nitro. My past experience has shown me that, once I'm
advanced on
a topic, I lose the perspective that's required to teach a
newbie the
first steps.
So, that said, here's my idea of how I'll proceed, and if I
record my
steps, it could be the framework of tutorial.
Only the first two sections seem clear...
I
Simplest possible demonstrations of:
1) Nitro.start ( examples/hello )
2) Controllers
3) Templates ( two or three examples in a single
application )
4) Og and admin ( a single table )
II
The second set would begin by introducing application layout
( what gen
produces ), and
use that to cover the following in more depth:
1) Move from Nitro to Application, including dispatcher
2) Multiple controllers
3) Larger, nicer looking templates, xml, js, etc.
4) A larger, more useful subset of Og functionality (
relationships,
etc. )
III
Overview
1) Libraries and their roles
2) Configuration, initialization
3) Architecture
4) Parts
IV
A Real World Solution
1) Ajax and Javascript
2) RSS, XML, etc.
3) Best practices (?)
4) Application Design
5) More Og tricks
V
Advanced Topics
???
Here, for example, is a first-cut at an Og and admin
demonstration for
the first section:
|
======================
File: ./README
======================
Simple demonstration of Og: Nitro's database layer and ORM.
Invoking "ruby -rubygems app.rb" initializes a
sqlite database
and starts an HTTP server on port 9000.
Due to Nitro's admin scaffolding you can begin working with
the database
immediately.
Assumes you've got sqlite3 and the ruby sqlite3-ruby gem
installed.
If not, and you've got postgres or mysql, modify Og.start in
app.rb:
For mysql
#
# Og.start(
# :name => "mydb",
# :adapter => :mysql,
# :user => 'root',
# :evolve_schema => false # true
# )
For postgres
#
# Og.start(
# :name => "mydb",
# :adapter => :postgresql,
# :user => "postgres",
# :password => "postgres",
# :evolve_schema => false
# )
|
|
#========================================================
# File: app.rb
# First Og demo
#========================================================
#
# Demonstrates Nitro's Object-Relational database
# layer. Similar to ActiveRecord, but much more
# intuitive for OO programmers
#
# Invoke using "ruby -rubygems app.rb"
#
# Should start up instance with WEBrick on port 9000.
#
# Index page will direct you to /admin, which allows
# you to use Nitro's scaffolding to manipulate database
# records.
#
#========================================================
# require glycerin if running from source checkout
#
# glycerin modifies ruby paths to pick up nitro from
repository checkout.
# there may be conflicts if nitro gems are also installed on
machine.
#
require
"#{File.dirname(__FILE__)}/../../script/glycerin"
require 'nitro_and_og' ## boilerplate require
include Nitro ## must include module for
functionality
require 'item' ## Og will recognize 'item' aw our
database
object ( see item.rb )
require 'test_controller' ## our controller.
#
# admin part serves as scaffold for database editing
#
require 'nitro/part/admin'
#
# Start og. Database is created if it doesn't already
exist
#
Og.start(
:name => "items", ## database name
:adapter => :sqlite, ## see README if you don't have
sqlite3
:evolve_schema => false ## true
)
Nitro.start TestController ## nitro automatically creates
controller
from class
|
|
#======================
# File: ./item.rb
# data model for Og demo
#======================
#
# A simple 'require' is all that's needed for Og
# to find this file and treat it as a database object
# ( table ) definition.
#
class Item
# type must be defined for Og to pick up fields
# Otherwise Og will ignore this -- it won't become a
table
attr_accessor :content, String
attr_accessor :source, String
attr_accessor :title, String
## "name" is helpful for scaffolding library.
## admin part displays 'name' when listing records
def name
title
end
end
#============================
# File: ./test_controller.rb
#
# For convenience, http://localhost:9000/
# provides a link to admin functionality
#
#============================
class TestController
def index
render_text "<a
href='/admin'>Admin</a>"
end
end
|
_______________________________________________
Nitro-general mailing list
Nitro-general rubyforge.org
h
ttp://rubyforge.org/mailman/listinfo/nitro-general
|