views:

1162

answers:

2

I have this quiz rails app linked to an IRC bot who asks questions (yes, on IRC), where I have this Question model which contains, well, questions, answers, hints, and a few more things.

I started with Quiz model (like, say, the special Halloween or Christmas quiz) with a quiz_id in the questions table, then, I told myself, that it would be nice to be able to categorize the questions, so I added a Category model (like, say, Movies or Books), with a category_id in the questions.

Now, my users would like to be able to add a question to one or more quiz, and to assign one or more categories to questions…

So, I've been thinking about removing the Quiz and Category models and replace them with tags, so that, there will be a halloween tag, a movie tag, and a question can have "halloween movie christmas" for tags.

In my searchs, I've seen quite a few ways to include tags like acts_as_taggable, acts_as_taggable_on_steroids or whatever else someone has imagined :-)

Now, I'm wondering what I should do, and so, I'm asking, what you have done, how you've done it, why you did it this way.

+2  A: 

I think Category can easily be replaced by tags, because they are both used to add metadata to a question.

However, I have my doubts about the Quiz model. If you only use the Quiz model to group your questions, it could be possible to replace it with tags. But I think the Quiz model will include more functionality than just grouping alone. For example, score keeping, picking the next question, etc. So I would keep the Quic model intact.

To implement tagging, acts_as_taggable_on_steroids does work, but is a bit old. It would be nice to have a tagging plugin that uses named_scope in the background, as it would make the plugin far more flexible.

wvanbergen
+1  A: 

acts_as_taggable_on_steroids is older, but it still works, and is still being maintained. Be sure you're visiting the primary repository for it:

http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids/

You can use acts_as_taggable_on_steroids with named_scopes, here's an article that shows how:

Speed Up and named_scope acts_as_taggable_on_steroids Finds

The actual addition to your model is pretty trivial (this is directly from the article above):

named_scope :tagged_with, lambda { |tags| YourModel.find_options_for_find_tagged_with(tags) }
Alderete