ItsJoeTurner/Idea-Book — pull request #1 by hannesfostie (2013-09-05 18:05:10+00:00)
Title: Add more advanced associations for User roles

Hey Joe

So here's what I did:

- I restructured the routes, as you probably want to nest them anyway. They'd look like this: /brands/:brand_id/projects/:project_id/ideas/:id
NOTE: I didn't do this for agencies, as a User only has access to one agency. Upon logging in you can use a current_agency helper to find the brands that user has access to.
- I added an admin namespace, so that when you go to /admin/agencies you can handle management of the agencies as an admin of the application. You can use a before_filter on an AdminController (which inherist from an ApplicationController most likely) to check if the currently logged in user is an admin.
- Added a super_user attribute to User, as well as a conditional association. If you set super_user to true on user1, but not on user2, you will see this:

```
agency.super_users # => [user1]
agency.users # => [user1, user2]
```

This, combined with a simple check to see if that user is a super user, will help you to allow or deny certain actions in your controllers

I noticed some of your model have a model_name_id attribute (as in, Agency has an agency_id attribute) - is there a reason for this? It looks unnecessary, but I didn't look through all of the code. agency_id on the User model makes perfect sense of course, but not on the Agency model.

To be honest, this is only the first step towards what you need. I'm not sure exactly how far you want me to go here... I could explain things in more detail if required, or go a bit further in adding those features, just let me know what you need more help with.