Skip to content

bemurphy/pundit_helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PunditHelpers

Authorization helpers for Pundit

Installation

Add this line to your application's Gemfile:

gem 'pundit_helpers'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pundit_helpers

Usage

In your base controller or controllers that need Pundit:

class ApplicationController < ActionController::Base
  include Pundit
  include PunditHelpers
end

The helpers currently add an #authorized? method that is useful for letting Pundit know that you have checked authorization so that the verify_authorized after filter doesn't raise an exception, and returns false for failures rather than raising.

authorize(post, :show?) # Returns true or raises Pundit::NotAuthorized on failure
authorized?(post, :show?) # Returns true or false

Also, this adds a #can? method ala CanCan. Passing can? an action and record will return a boolean and is useful in views. For example:

<% if can? :edit, @lesson %>
  <a href="/posts/42/edit">edit</a>
<% end %>

Contributing

  1. Fork it ( http://github.com//pundit_helpers/fork )
  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 new Pull Request

About

Authorization helpers for Pundit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages