Skip to content
CanCan integration for ActiveAdmin
Ruby JavaScript
Find file
Latest commit b8e7edc Sep 14, 2012 @11factory support :as option for ActiveAdmin.register
When I have:ActiveAdmin.register Profile, as: "User" do it should authorize the Profile resourc
Thanks to bagilevi!
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
Gemfile
Gemfile.lock
MIT-LICENSE Documentation Mar 1, 2012
README.rdoc
Rakefile
activeadmin-cancan.gemspec

README.rdoc

ActiveAdmin-Cancan

ActiveAdmin-Cancan provides a smooth integration of the two gems ActiveAdmin and Cancan.

Getting Started

Active Admin - Cancan is released as a Ruby Gem. The gem is to be installed within a Ruby on Rails 3 application. To install, simply add the following to your Gemfile:

gem 'activeadmin-cancan'

Configure CanCan

You just have two things todo

1. Create the CanCan ability class

User permissions are defined in an Ability class. CanCan includes a Rails 3 generator for creating this class.

rails g cancan:ability

See CanCan page [github.com/ryanb/cancan/wiki/defining-abilities] for details.

2. Handle Unauthorized Access

If the user authorization fails, a CanCan::AccessDenied exception will be raised. You can catch this and modify its behavior in the ApplicationController.

class ApplicationController < ActionController::Base
  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_url, :alert => exception.message
  end

  def current_ability
    @current_ability ||= Ability.new(current_admin_user)
  end 
end

See CanCan page [github.com/ryanb/cancan/wiki/exception-handling] for more information.

How it works

I have just made the integration between the two gems, the two steps above are the only ones todo to get roles working with ActiveAdmin.

Copyright

Copyright © 2012 Laurent Cobos, 11Factory. See LICENSE for details.

Something went wrong with that request. Please try again.