3

I'm working with a large list of abilities for users with different Role types on a rails application. This is with the CanCanCan gem.

It has gotten quite large, and I have non-dev users who want to be able to see a run-down of abilities for different users. How can I represent the existing abilities on a user interface?

i.e.

class MyUserAbilityController < ActionController::Base

  def show
    @abilities = current_user.abilities
  end

  def index

    @full_abilities = Hash.new

    Role.all.each do |role|
      @full_abilities[role.name] = role.abilities
    end

  end

end

And then pass it along to the view?

Further, although not necessary, is there a way I can dynamically change or alter the CanCanCan abilities from an external source?

I have been playing around with it in the Terminal for now, with an eventual goal to be able to have some basic rule-setting (not creation, but perhaps changing 'can's to 'cannot's) on an admin user interface with radio buttons.

-Schwad

Nick Schwaderer
  • 1,030
  • 1
  • 8
  • 21
  • Not really related to your question, but if this is a newer project you probably should be using the CanCanCan gem. It is the maintained fork of the now defunct CanCan gem https://rubygems.org/gems/cancancan – bigtunacan Apr 13 '16 at 13:47
  • I agree, cancancan is happening. – Nick Schwaderer Apr 13 '16 at 21:31

1 Answers1

1

I have decided to develop a gem to solve this answer, it's still very much in development, but soon fit for purpose. It's called CanCanCanSee.

Check it out here

It brings you the method CanCanCanSee.all_abilities to render a hash of existing abilities and roles.

Also if you want to run a pretty printed version of your abilities from the Terminal (think like you do with rake routes) you have CanCanCanSee.pretty_print_abilities

Thanks!

Nick Schwaderer
  • 1,030
  • 1
  • 8
  • 21