EppO/rolify — Issue #30: Suggestion: create a mirror module for the resources
Author: hazah
Created: 2012-01-13 12:58:12+00:00
State: open

Like the User having roles on resources, resources have many roles from Users. I believe all this amounts to creating the has_many association on each resource model.

```ruby

has_many :roles, :as => :resource

```

It would add the benefit of allowing an authorisation system to scope a resource to a set of roles. I imagine the interface to be dynamic methods for each resource class:

```ruby

user.roles.first(:name => 'update', :type => 'Post', :resource_id => params[:id]).posts

# or

user.roles.first(:name => 'update', :type => 'Post', :resource_id => params[:id]).posts.find params[:id]

```

Note: I am not suggesting using raw associations in client code. I left it verbose and 'raw' on purpose to illustrate all the relationships.

```ruby

moderator.roles.first(:name => 'update', :type => 'Post').posts

# or

moderator.roles.first(:name => 'update', :type => 'Post').posts.find params[:id]

```

Thoughts?