I’m very new to Rails, and I’m having trouble deciding where to put some
code I wish to share across my applications, and possibly with the
Here’s the scenario:
I’m developing a personal website, to contain images, blogs, videos,
etc. I’d like users to be able to comment on all these things.
Now I could create a ‘comments’ table and stick a ‘type’ field in there
inherit all the actual model classes from Comment. This gets the job
but I wind up with a bucket load of redundant code, especially in the
Am I missing some base Rails functionality here? Can I associate all my
other models to the Comment model simply? It’s entirely possible I’m
missing something easy. If so, please point it out.
Assuming I haven’t missed something really easy, I’ve been looking for a
to easily encapsulate the code to do comments.
I’ve created a ActiveRecord extension called ‘is_commentable’. Which is
just a thin wrapper around ‘has_many’ that adds the class name to the
field. I’ve added a helper that takes an object and checks to see if
‘commentable?’ and if so renders the associated comments.
Engines seem like a good fit, because I want end to end functionality.
want to drop in comment_engine and be able to start commenting my other
I’m just in search of a sanity check. I’d like to learn to do things
correct way, and with something as flexible as Ruby/Rails the ‘right
isn’t always clear.
Thanks in advance.