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
endThe 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 falseAlso, 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
- Fork it ( http://github.com//pundit_helpers/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request