Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on your question, it sounds like you're trying to build an ACL and a metadata storage system at the same time. This can be a little tricky to sort out.</p> <p>Generally in a role-based system you have several patterns to follow, but usually some combination of the following:</p> <ul> <li>Users have system-wide privileges based on a type of authentication level.</li> <li>Users have system-wide privileges that are granted by the user having one or more roles.</li> <li>Users have different privileges based on their authentication level in the context of specific resources.</li> </ul> <p>You might be describing the first or second case depending on the nuances of it. Here's an example of the first:</p> <pre><code>class User &lt; ActiveRecord::Base belongs_to :role end class Role &lt; ActiveRecord::Base # Defines methods to determine ACL privileges end </code></pre> <p>The second is a bit more flexible, but is also slower when trying to resolve a simple yes/no case because more roles must be checked.</p> <pre><code>class User &lt; ActiveRecord::Base has_many :grants has_many :roles, :through =&gt; :grants end class Grant &lt; ActiveRecord::Base belongs_to :user belongs_to :role # Defines methods to determine ACL privileges end class Role &lt; ActiveRecord::Base # Defines methods used by Grant ACL implementation end </code></pre> <p>If you need to have some kind of configuration or meta-data stored about what each role provides for the user, put that into the Grant model as additional fields.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload