The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

acts_as_list sort by multiple items

I have a Person model and I'm using acts_as_list so I can have drag/drop positioning of people. The only thing is, I want to be able to differentiate between male and female, ie. sort males separately from females. It seems completely useless to have two separate models since all the other attributes of a person are the same (name, address etc) Does acts_as_list allow ordering by, say, position and sex so I can just keep one model and have some males positioned from 0-x and females positioned from 0-y ? x&y being the # of males/females respectively

In writing this, I also just thought, maybe I can create a person model and have a male/female model extend from this with attribute sex, then use acts_as_list on the male/female model. I'm not sure i would know how to design the db for that.

From an OO perspective, this makes sense. but in rails I'm not so sure. I don't want a separate db table for male/female, so it all has to be stored in Person. The whole point is to not use two separate db tables for male and female. But in my controller, if I create a new Person, i can check params[:sex] and either create Male or Female depending. I still don't know if this will work as far as the sorting. I'll have acts_as_list for each male/female but if I make a sort function in my male controller, and I call Male.update_all I can't visualize how rails could possibly only select the males from the Person db given that the Male class is basically just virtual. Ugh, i'm pretty confused here, if anyone has insight, it's greatly appreciated

Hi, thanks for the response. I had no problems retrieving separate male/female columns, the problem was that acts_as_list automatically adds the new position as the max of all items in the scope.

I ended up using one class as I wanted. and i just didnt use acts_as_list at all. I made my own function to get count of males and females, so when I create a male or female, it sets the position appropriately

Don't know why I didn't just think of that in the first place, it's pretty simple Likewise I wrote my own delete function to update all positions appropriately