Note that there are some explanatory texts on larger screens.

plurals
  1. POCanCan vs. Rails Association
    primarykey
    data
    text
    <p>I think I have gone and confused myself over the power of CanCan.</p> <p>I asked a longer question here - <a href="https://stackoverflow.com/questions/13717456/rails-has-many-through-null-belongs-to-multiple-belongs-to-and-deletion-of-be">Rails has_many :through, null belongs_to, multiple belongs_to and deletion of belongs_to?</a>. But at the advice of one of the members, I simplified my question with what I think is my ultimately question.</p> <p>In short, a <code>User</code> has a <code>Role</code> in a <code>Network</code>. A <code>User</code> can also create <code>Events</code>, however, what <code>Events</code> they can see/edit are all based on that <code>Role</code>. If a <code>User</code> loses their <code>Role</code> they no longer have access to an <code>Event</code>.</p> <p>Additionally, if the <code>User</code> and/or <code>Role</code> that created the <code>Event</code> is removed, the <code>Event</code> will still exists in the <code>Network</code> and be visible to all <code>Users</code> with a high enough authority (admin, manager, etc.) in their <code>Role</code>.</p> <p>I can use CanCan to determine if a <code>User</code> has access to an <code>Event</code> by testing their <code>Role</code>. That part is working fine.</p> <p>But more conceptually, if I am using CanCan to control both the access to the controller actions for <code>Events</code> as well as whether or not the <code>Event</code> is even displayed in the view based on <code>can :read</code>, is there a need for an rails <code>has_many :through</code> association between <code>Users</code> and <code>Events</code>? Since technically the <code>User</code> is only connected to the <code>Event</code> through a <code>Role</code> in a <code>Network</code>, can I just leave it to CanCan to control access, or do I need an association. Would it be good to have a method like:</p> <pre><code>def events ... # info for grabbing all events user has access to? end </code></pre> <p>Or is that also unnecessary?</p>
    singulars
    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.
    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