# REST, Nested Routes and Best Practices

**URL:** <https://www.ruby-forum.com/t/rest-nested-routes-and-best-practices/154973>\
**Category:** Rails\
**Created:** [December 5, 2008, 6:43pm UTC](https://www.ruby-forum.com/t/rest-nested-routes-and-best-practices/154973 "2008-12-05T18:43:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmgreeley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/34f0e0/32.png) [@bmgreeley](https://www.ruby-forum.com/u/bmgreeley)\
**Post date:** [December 5, 2008, 6:43pm UTC](https://www.ruby-forum.com/t/rest-nested-routes-and-best-practices/154973/1 "2008-12-05T18:43:10Z")

</div>

Hi everyone,

I am trying to strictly adhere to REST and I have a few code  
organization questions.

My database tables are as follows:

USERS  
GROUPS  
GROUP\_USERS  
EVENTS  
EVENT\_USERS

The relationships are as follows:

GROUPS have many USERS and USERS have many GROUPS.  
EVENTS have many USERS and USERS have many EVENTS.

So, right now, I have a controller for users, groups and events. I got  
to the point where I want to have USERS add themselves to a GROUP and/or  
an EVENT. Before I add methods to the group or event controller  
specifically that are called something like add\_user, delete\_user,  
edit\_user … I want to get everyones take on my problem.

* * *

Here is my question:

Should I either (a) create a new controller for GROUP\_USERS and  
EVENT\_USERS that handles the GROUP/USER and EVENT/USER relationships

OR

Should I (b) reuse the user controller code and in “def create” check to  
see if there is an event\_id or group\_id present and then add the user to  
either the group or event there?

* * *

Or, I guess, is there a better way to handle this?

Thanks a ton in advance,  
Brandon

---

<div class="post-metadata">

**Author:** ![bmgreeley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/34f0e0/32.png) [@bmgreeley](https://www.ruby-forum.com/u/bmgreeley)\
**Post date:** [December 5, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/rest-nested-routes-and-best-practices/154973/2 "2008-12-05T21:11:27Z")

</div>

On Dec 5, 11:43 am, Brandon G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> EVENTS  
> specifically that are called something like add\_user, delete\_user,  
> Should I (b) reuse the user controller code and in “def create” check to  
> Posted viahttp://www.ruby-forum.com/.  
> I think you would benefit a Memberships controller (or something like  
> that), that would handle the adding/removing of users to and from  
> groups. You might also want a corresponding membership model (though  
> it’s not totally necessary, but many people find it helpful).

That way, your Users and Groups controllers stay “clean”, and you  
isolate the membership-ness stuff to a separate controller.

Jeff

[purpleworkshops.com](http://purpleworkshops.com)

---

<div class="post-metadata">

**Author:** ![bmgreeley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/34f0e0/32.png) [@bmgreeley](https://www.ruby-forum.com/u/bmgreeley)\
**Post date:** [December 5, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/rest-nested-routes-and-best-practices/154973/3 "2008-12-05T22:37:40Z")

</div>

Jeff C. wrote:

> On Dec 5, 11:43ï¿½am, Brandon G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > EVENTS  
> > specifically that are called something like add\_user, delete\_user,  
> > Should I (b) reuse the user controller code and in “def create” check to  
> > Posted viahttp://www.ruby-forum.com/.  
> > I think you would benefit a Memberships controller (or something like  
> > that), that would handle the adding/removing of users to and from  
> > groups. You might also want a corresponding membership model (though  
> > it’s not totally necessary, but many people find it helpful).
> 
> That way, your Users and Groups controllers stay “clean”, and you  
> isolate the membership-ness stuff to a separate controller.
> 
> Jeff
> 
> [purpleworkshops.com](http://purpleworkshops.com)

That sounds like a good option. I really didn’t want to muddy up the  
users controller at all and keep them clean like you said.
