Isaac Sloan - Petergate Authorizations

Petergate Authorizations

"If you like the straight forward and effective nature of Strong Parameters and suspect that cancan might be overkill for your project then you'll love Petergate's easy to use and read action and content based authorizations."

-- I proclaim optimistically


Add this line to your application's Gemfile:
gem 'petergate'
And then execute:
Or install it yourself as:
gem install petergate
Setup Authentication

Make sure your user model is defined in app/models/user.rb and called User.

If you're using devise you're in luck, otherwise you'll have to add following methods to your project:

Finally you can run the generators
rails g petergate:install
rake db:migrate

This will add: ruby petergate(roles: [:admin]) to your User model.


Setup permissions in your controllers the same as you would for a before filter like so:

access all: [:show, :index], user: {except: [:destroy]}, company_admin: :all

# one other option that might seem a bit weird is to put a group of roles in an array:
access [:all, :user] => [:show, :index]

Inside your views you can use logged_in?(:admin, :customer, :etc) to show or hide content.

<%= link_to "destroy", destroy_listing_path(listing) if logged_in?(:admin, :customer, :etc) %>

If you need to access available roles within your project you can by calling:

# or from an instance
# ROLES is a CONSTANT and will still work from within the User model instance methods
# like in this default setter:

def roles=(v)
  self[:roles] ={|r| r.size > 0 && ROLES.include?(r)}


PeterGate is written and maintaned by Isaac Sloan and friends.

Currently funded and maintained by RingSeven



  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
January 18, 2015
rubyrailspunditcancan alternative
comments powered by Disqus