Subject
Message This is a sample forum written as a quick intro to Ruby and Rails.
The only table used is:
CREATE TABLE posts ( id int(19) NOT NULL auto_increment, subject varchar(255) NOT NULL default '', message text NOT NULL, author varchar(255) NOT NULL default '', email varchar(255) default NULL, url varchar(255) default NULL, created_at datetime default NULL, post_id int(19) default NULL, type varchar(255) default NULL, PRIMARY KEY (id) )
require 'active_record' require 'forum_controller' class Post < ActiveRecord::Base def before_destroy sqlId = ForumController.quote(id) Comment.find_all("post_id = #{sqlId}").each do |entry| entry.destroy end end end
require 'post' class Comment < Post belongs_to :post # it is assumed the foreign_key => "post_id" # however, manually assigning a foreign key # will work also too. end
Author
Email
Url
Created at 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 January February March April May June July August September October November December 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 — 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59