Routing Question

So I have a routing problem I'm running into.

I have a model called Film, and each Film belongs to categories, which
are being store in the DB as a serialized array in the category column.

The films_controller is working right now with index, new, edit, delete
actions. All is well using the default rails routing scheme.

What I want to do is keep the films_controller as close to as it is now,
but allow the user to view films by category using a url like this

/admin/films/:category/:action/:id

without loosing the ability to manage all films using urls like this:

/admin/films/:action/:id

I've tried setting up a route like this, both before and after the
default rails routes:

map.admin_films 'admin/films/:category/:action/:id', :controller =>
'admin/films'

When I place it before the default rails routes I get the category pages
working, but the global actions (/admin/films/edit/1) error out with the
following error:

'No action responded to 1'

When I place it after the default rails routes the category pages don't
work and I get the following error:

'No action responded to narrative_features'

(narrative_features being on of the categories films can belong to)

Any help is appreciated.

What you first want to do is to create a separate categories model and
probably have an habtm relationship between films and categories (a film
can have many categories and a a category can have many films). You
should (generally) not do things like serialized arrays in database
columns for things that are logical entities in your model. Basically,
this is not a "normalized" database.

For example, if you delete the last film that was part of the category
"Western", you would no longer have "Western" as a category.

Paul

Oh, and as far as the issue regarding routes, you might need to use
regular expressions to help defined "Pretty URLs"

http://api.rubyonrails.org/classes/ActionController/Routing.html

Paul Hoehne wrote:

What you first want to do is to create a separate categories model and
probably have an habtm relationship between films and categories (a film
can have many categories and a a category can have many films). You
should (generally) not do things like serialized arrays in database
columns for things that are logical entities in your model. Basically,
this is not a "normalized" database.

For example, if you delete the last film that was part of the category
"Western", you would no longer have "Western" as a category.

Paul

I tottally hear ya. I did this knowing it was lazy development, and that
I would have to rewrite it eventually.

In regards to the routes. Will I use a regex that checks to make sure
that the :category matches only the available categories? Not sure how
that is going to solve my problem.

Thanks.