Skip to content
/ doodoo Public

A gem to help with authorising controllers with cancan

License

Notifications You must be signed in to change notification settings

2rk/doodoo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doodoo

A set of tools to help with CanCan. Doodoo provides a module for use with Rails controllers that assists with authorisation, especially with nested routes.

Installation

Add this line to your application's Gemfile:

gem 'doodoo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install doodoo

Usage

Add to ApplicationController:

include Doodoo::NestedLoadAndAuthorize

And then in controllers (For example a TasksController, nested under ProjectsController):

before_action do
  # load task nested under project, only if params[:project_id] exists:
  load_and_authorize_if_present :project do
    load_and_authorize :task
  end

  # enforce nested load:
  load_and_authorize :project do
    load_and_authorize :task
  end

  # and for a shallow route:
  load_and_authorize :task

  # load without authorisation:
  load_resource :task

  # only specific actions
  load_and_authorize :task, :only => [:show]

  # supply a condition in should_load_task? method (can use a proc here too)
  load_and_authorize :task, :if => :should_load_task?

  # specific id parameter for another action:
  load_and_authorize :task, :id_param => :task_id, :only => [:other_action]

  # only load if parameter present in menu:
end

Contributing

  1. Fork it ( http://github.com//doodoo/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

A gem to help with authorising controllers with cancan

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages