Feb 17 2007
Another Ruby-on-Rails Gripe: “acts_as_list”
Okay, working on my web app using Ruby on Rails, and I just encountered a new gripe. Now, it may be a newbie gripe, or it may be a genuine issue — I’m not so sure. I’m looking for help if anyone’s got it, but I’m not finding it in either of the $40 books on Rails I’ve got at hand.
Let me first set the stage. In application models (this is “models” as in “Model-View-Controller”), you will often have a relationship between two models. And these models can be represented in a number of ways: for instance, one model might contain a list of instances of another model. Unfortunately, the coding for that model is done in the model within the list, not the model having the list. Which means, as far as I can tell, that every model can only be in a single list. And I’ve encountered a modelling situation where I want a model to be in multiple lists.
So how do you solve this in rails? For the time being, I’ve created intermediary models anywhere I want there to be a list (similar to using a model to represent a join). There’s got to be a better solution.
Popularity: 2% [?]
Temporary solution: overwrite the nice auto-generated method provided by
has_manyandacts_as_listwith a one-liner query that returns a list of the item.