0

Ok, this gives me some headaches!

I have a many-to-many relationship with a link table that has a few attributes on its on:

user linked to items through ownings

The active-record part is clear to me. But what are my resources here? Clearly there are users and items. Items are going to be managed on their own. I want to link users to items from the users view having a link to a page where the items of the user are shown (and can be remove from that particular user) and a link to a page where new links between the user and an existing item can be created (also entering the link table attributes).

Would you manage that by putting more user defined methods/routings in the user controller or would you have another controller as subresource of the user controller?

What confuses me is that resourceful routing takes you by the hand and says, that on a theoretical basis you have these x methods, that is probably all you gonna need. And than the rails routing guide for example has a hole lot more text to show you what else you can do to tweak around with resourceful routing. But at that point I feel left alone since I don't know what to tweak! Only two hints are given: Do not nest resources more levels deep than one and do not ad user defined methods a lot.

Do you know what to do or what book/guide would you recommend for these kind of questions.

lucapette
  • 20,564
  • 6
  • 65
  • 59
user331471
  • 873
  • 1
  • 9
  • 19
  • So you have at least two models: User and Item. It's not clear if you have one but you also want a "join model" called something like UserItem. In your routes you want to nest user_items (1 level) inside of users and in the Item model add `accepts_nested_attributes_for :items` So you end up with a path like `/users/1/items/1`. – Tom L Feb 01 '12 at 15:06
  • Take a look at this: http://stackoverflow.com/questions/3714014/use-accepts-nested-attributes-for-to-create-new-records-or-update-existing – Tom L Feb 01 '12 at 15:15

0 Answers0