Cancancan is one best tools to do this in Ruby. Maybe its DSL-like syntax will give you better ideas.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;CanCanCommunity&#x2F;cancancan" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;CanCanCommunity&#x2F;cancancan</a>