Topic: HABTM Listing by category, and sub-category filters.

my models:

class Exercise < ActiveRecord::Base
  has_and_belongs_to_many :categories
  has_and_belongs_to_many :subcategories
end
class Subcategory < ActiveRecord::Base
  has_and_belongs_to_many :exercises
end
class Category < ActiveRecord::Base
  has_and_belongs_to_many :exercises
end

First off, I'm new to ROR. I've only been working with it for the last few weeks.  I find it interesting, but not always easy to make the conceptual breakthroughs needed to advance as fast as I like. 

I am trying to create an online database of exercises, which can belong to many categories, and sub-categories.

It's easy enough to list all the exercises, but I also need to list only those belonging to the various categories, or sub-categories.

There are two ways I want to approach this:

1. when listing the exercises, the category, and sub-category, columns show the appropriate categories, and sub-categories which will link to a filtered listed of only those chosen by the user.

For example:

Exercise A, belongs to categories CA,CB,CC and subcategories SCA, SCB, and SCC
when listed, the categories column shows > CA,CB,CC which are clickable links that would filter the list by which one is clicked. clicking CB will show all exercises belonging to category CB.

2. a series of two linked select boxes [Categories][Sub-Categories] such that when a user selects a Category from the populated list box and the Sub-Category from the next list box, and then clicks 'GO' he will be presented with only the exercises that fill the criteria of both, or just one, or the other if only one is specified and the other isn't.

Does this make any sense, what I need to do?

If so, can someone, anyone, please help me figure this out.

I think my main problem is... ROR. smile

Thanks,
Alan Pieroway

Last edited by alanpieroway (2006-11-14 00:17:08)