Skip to main content
0 online
deanh77 May 25, 2006

rails is ridiculously easy for this kind of application, sorry I'll try to read mor of this and post some pointers, but wiki.rubyonrails.org is amazing.

iwz iwz

i've started the work. i've been fixing up me schema a lot, and i've got some of the basic functions of the site up and running locally.

in a few days, i'll be ready to check the code into SVN or CVS and get some real development started.

deanh77 deanh77Founder

yeah. that's the most important part. make sure your relationships are good. Also you should look into "Single Table Inheritance"

for example

class Topic
end

class ForumThread < Topic
end

class Journal < Topic
end

you'd have one table like:

CREATE TABLE `topics` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) default NULL,
`author_name` varchar(255) default NULL,
`written_on` datetime default NULL,
`content` text,
`type` varchar(50) default NULL,
PRIMARY KEY (`id`)
);

j = Journal.create(:title=> 'my journal', :author => 'me', :written_on => Date.new, :content => 'some content here')

would create a record in the 'topics' table with the 'type' field set to 'Journal'

Basically, you get and save Journal objects as if they were in their own table. And you can also get all Topics (be they Journals, ForumThreads or whatever) by performing operations on the supertype "Topic"

Topic.find(:conditions => ...)

ActiveRecord is a really really cool framework.

(I stole some of this from http://wiki.rubyonrails.com/rails/pages/Inheritance, which just happened to explain STI using a Topic and a Reply class.)

iwz iwz

i definitely gotta do it that way!

i do it like that in the current Java code now, to a certain degree.

but if i clean up the schema a bit more, this could really shine.

deanh77 deanh77Founder

yeah. I haven't looked at ezabel schema in a while, but I remember you doing something like this. But the difference in Rails is, its part of the ActiveRecord framework. good support for this kind of thing.

iwz iwz

yeah that's really sexy. it figures out the type by the class name?

part of the problem is that I have different tables for everything

news, journals, threads, faqs, events.. all different tables.

i'm pretty sure i could merge news, journals, and threads. but some of the tables have columns specific to the type. i would have to either decide whether or not i really need the extra attributes, or just merge them all in. or have a child table by type or something.

deanh77 deanh77Founder

yeah, that is a slight drawback to STI. it's illustrated here:
http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html

all properties of all classes in the inheritance tree are present in the table as fields.

but its not really a problem, as the unused fields are just left unpopulated.

iwz iwz

yeah that works. sti helps with searching too.

iwz iwz

So, i wrote a migration to create a topics table to merge news, forum_threads, and journals into one table. I combined all the columns. There's only a few that aren't shared, so that's not bad.

Got it working, seems pretty nice.

The only thing I'm wondering now is... do I need separate controllers for each of the models now? So much of the logic is the same, and I want to keep it DRY. Any ideas on sharing some of the logic?

D
dgiaimoOG 2003

Any chance any of us mortals could look at the schema? :) I'd really like to see how it's organized.

iwz iwz

def. i'll have something to show you in a few days (after i'm done cleaning everything up).

the bad part is that i'm using MyISAM tables in MySQL instead of InnoDB. So, there's no foreign keys and no transactions right now.. works good enough though :)

iwz iwz

here's the schema after a hefty clean-up. there's still a lot of cleanups to do, but it's much better than it was. i'll fix the remaining problems as i go.

/files/out.txt

deanh77 deanh77Founder

you should be able to turn that into some Model classes pretty easily. at least with some of the relationships

iwz iwz

Yeah. I've only made some of the models so far. Like, I've got the homepage working with news stories, and forums and threads all working. Comments come up in a basic layout (no threading yet). Login is (was) working. And Journals are working.

I haven't gone through and done much more than what the scaffolding provides for most parts, yet. Have to make the forms pretty, and fill in all the needed stuff on saves that shouldn't be entered by form.

I think my next step is to set up Migrations to make the db part easier.

iwz iwz

loving Rails Migrations! ( http://media.rubyonrails.org/video/migrations.mov )

i've been evolving my schema a bit using the feature, and it really makes things nice.

deanh77 deanh77Founder

yeah, that's one thing I hadn't looked into, but I probably should have on my rails project...

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.