Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Padrino can can use all CanCan goodies

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 padrino-cancan.gemspec
README.md

CanCan for Padrino

Padrino can can use all CanCan goodies

Using

Add to your Gemfile

gem 'padrino-cancan'

Run

bundle

Register in your app

class MyApp < Padrino::Application
  register Padrino::CanCan

  ...

Define how you want access denied to be handled

  error CanCan::AccessDenied do
    403
  end

Add some abilities for some roles

  role [:any, :external, :manager, :manufacturer, :admin] do
    can :index, :base
    can [:index, :view, :find, :search], Product
  end

  role [:external, :manager, :manufacturer, :admin] do
    can [:edit, :update], :account => account
  end

  role [:manager, :admin] do
    can [:create, :destroy], [Brand, Factory]
    can :manage, Product
  end

  ...
end

refer to CanCan wiki to learn how to define abilities syntax ("can" method)

In your controller

App.controllers :products do
  get :index do
    authorize! :index, Product
    ...
  end

  get :view, :with => :id  do
    authorize! :view, Product
    ...
  end

  ...
end

In your views

-if can?(:destroy, Product)
  %li=link_to 'Destroy', url(:products, :destroy, product.id), :confirm => pt(:confirm)
-if can?(:edit, Product)
  %li=link_to 'Edit', url(:products, :edit, product.id)

Author

Created by Phil Pirozhkov

Origin

Future

Remove studid instance_eval. Check for extra initialization which may be cached. Go back to initial abilily/role/can syntax. Write tests.

Something went wrong with that request. Please try again.