Forum: Ruby on Rails Single controller to browse things in categories

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Si W. (Guest)
on 2005-12-20 04:58
First off, hi, I'm [obviously] new :O)

Please excuse my question as I'm sure it's been answered, but I can't
find it anywhere.

I have a table of categories:
id name
1 Foo
2 Bar

I have things which belong_to categories:
id category_id subject date
1 1 my subject 07/09/2004

and Further classifications which belong_to categories:
id category_id name
1 1 More Foo
2 1 Most Foo
3 2 Some Bar

and subcategories which belong_to categories, classifications, and
id category_id classification_id thing_id
1 1 1 some item
2 1 2 another item

I want my index to contain links to those categories:

By clicking on Foo, I'd like it to display things belonging to Foo, and
expand to show classifications
  - More Foo         (Foo Stuff)
  - Most Foo

It seems like I should be able to do this without having to create a
controller for each Foo, Bar, etc Category, but I can't figure out how.

If the standard index page shows categories, it seems as if I'm simply
adding a filter now to say "ok, get categories, but only if they are of
type X".

Again, sorry if this is a stupid question.  Thanks for any help you can
Si W. (Guest)
on 2005-12-20 05:46
I suppose I partially figured this out... I added the method to the
controller for that category name.  I suppose I could use a
method_missing type of thing to make this a little more dynamic, or is
that a bad idea?

Of course, now it complains about missing the view... what would I do
for that?
Ed S. (Guest)
on 2005-12-20 06:05
I came across that in the Agile Web D.  book (...plug)

Apparently, you can do a

ruby script/generate controller Admin::Book action1 action2 ...

to generate a Book controller and model within the Admin module.

which you would reference as

You would reference

class Admin::BookController < ApplicationController ,,,


class Content::BookController << ApplicationController

The first BookController would be in app/controllers/admin,

the second would be in app/controllers/content

The template for the first would be in


The template for the second would be in


Don't know if the scaffold generator supports this,
Si W. (Guest)
on 2005-12-20 06:29
err, nevermind, I think I figured this out... like I said, I'm new :O)
This topic is locked and can not be replied to.