nested routes with a 2-way has_many using join table?

I have two classes, InstructionalObject and Assets. They both have_many
of the other, implemented through a join table (so it's like a habtm
without the habtm).

For the next version of our app, we're refactoring to RESTful, and i'm
having trouble with my nested resources/routes. I tried this, in

  map.resources :assets do |assets|
    assets.resources :instructional_objects

  map.resources :instructional_objects do |instructional_objects|
    instructional_objects.resources :assets

thinking that would let me do


to get all the assets belonging to that instructional_object



for vice-versa.

However, when i go to these urls i get all assets, and all instructional
objects respectively: in other words, these two routes seem to be

  "instructional_objects/:id/assets" and "assets"

and these two are equivalent:

  "assets/:id/instructional_objects" and "instructional_objects".

To make life more confusing for myself (initially at least) i'm also
using resource_this in my controllers. Looking in the log, it looks
like the right request (i think) is going through:

Processing AssetsController#index (for at 2008-03-12 13:45:56)
  Session ID: 4ca8db0cc675a9dd71fc0ee96031f6ea
  Parameters: {"instructional_object_id"=>"0", "action"=>"index",

Can anyone help, please?

I understand the need to use has_many :through in both directions, but
does your _site_ actually need to present the data to users in both
directions? Sometimes this can be more of a theoretical need than a
practical one.

At any rate, if you're "going RESTful" with brand new controllers, the
controllers themselves need some help. They don't know anything about
the routing that directed the request to them so you've got to add
some code.

The main question that you need to answer is whether you ever need to
render an index that's not scoped. That is, will you ever need to
render a list of assets (all) rather than assets that are associated
to a particular instructional_object? If not then you can simply
modify your index method along these lines:

def index
  @instructional_object =
  @assets = @instructional_object.assets