Skip to main content
0 online
iwz Jun 6, 2006

Here's a design problem I'm running into. I have a bunch of different objects that all need to accept comments. Topics (News, Journals, ForumThreads) Single Table Inheritance Pictures Event...

yay Jun 7, 2006

The bottom line here is you really want to deal with a commenting functionality the same way for every entity, right? Personally, when it gets down to objects having similar fields sometimes it ...

iwz iwz

Yeah, I want to have common functionality.

Last night I worked on the problem a bit more using the existing schema (it's a big job to change the schema and update all the foreign keys in the comments table).

I came up with a RESTful URL scheme for posting comments:

/comments/new/:type/:id

For example, if you POST a comment to /comments/new/journal/256, it will take "journal" as the type, and use it like so:
@obj = params [:type].camelize.constantize.new.find(params [:id])

This retrieves the correct object to add the comment to, so then I just call
@obj.comments.build(params [:comment])

This is a partial solution to the problem. Gives me a central place to add comments to topics.

I'm still not happy with it overall, though. I mean, it works, but it's really not the cleanest solution.

deanh77 deanh77Founder

thats a pretty neat way of doing it. very DRY, but maybe a bit hack-ish. but if it keeps the code tight, it could be a good thing.

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.