Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Padrino can can use all CanCan goodies
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib stupid, ugly, but works
.gitignore
README.md Added link to example gist
padrino-cancan.gemspec initial

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)

Working example app.rb

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.