Ability class not found

27 views
Skip to first unread message

betasheet

unread,
Nov 23, 2011, 9:42:02 AM11/23/11
to cantango
Hi everyone,

we're trying to use CanTango in our web app. Somehow, it seems like
the CanTango Ability class is not used by CanCan as it says that it
cannot find the symbol "Ability".
We've configured CanTango in the cantango.rb initializer as follows.
If you need more configuration code, please just ask :)

CanTango.config do |config|
config.debug!
config.engines.all :on
# more configuration here...
config.ability.mode = :no_cache
end

We've also added "extend CanTango::Api::UserAccount::Ability" to our
application controller.
Are we missing something, or do we have to require a special module in
some class?

Thanks for your help
Eric

betasheet

unread,
Nov 23, 2011, 10:02:51 AM11/23/11
to cantango
Okay, problem found: We created a "troles" field in the database
schema, which seems like it is created automatically? Anyway, removing
it seems to have made the error go away.

Now, we're experiencing some problems with the permission store. We
define a "everyone can manage everything" permission in the YAML file:
user_types:
user:
can:
manage:
- all

But when testing the permissions, we get CanCan::AccessDenied
exceptions and the following appears in the console log:

valid_mode? false [:cache] false
No permissions for #<User:0x007f92452baca8> found for #all_permissions
call

We're slightly confused :P

Thanks
Eric

betasheet

unread,
Nov 23, 2011, 10:33:10 AM11/23/11
to cantango
We're getting the impression that the permissions.yml file isn't even
read at all. (We can put trash in it without causing an error and
removing it doesn't change a thing, too).
But if we put the following into our CanTango config, the console
shows, that the permissions module is loaded and looking for the YAML
file in the right location..

config.engine(:permission) do |engine|
puts engine.modes
engine.mode = :cache
engine.set :on
puts "ON" if engine.on?
puts "OFF" if engine.off?

# permission engine specific
puts engine.types # permission types available

# permission file location
#engine.config_path 'my/special/permissions/location'
#engine.config_path = 'my/special/permissions/location'
puts engine.config_path
end

Output:

cache
ON
roles
role_groups
licenses
users
user_types
account_types
/Users/Robin/SWT2/swt2_11_hasso/config

Kristian Mandrup

unread,
Nov 23, 2011, 10:54:36 AM11/23/11
to cant...@googlegroups.com
It might help you to clone the repo and run the relevant specs under the 'specs/cantango' folder, in order to better follow how to configure cantango and see what is going on...

betasheet

unread,
Nov 23, 2011, 11:43:55 AM11/23/11
to cantango
Thanks :) We've managed to get the file read. It seems to have been
because of "engine.mode = :cache". We're now using :no_cache, then the
permissions module starts up.
But we've ran into the next problem: The permissions for the admin
role are somehow applied to all of our users, no matter what roles
they have (it's applied even though user.role_list does not contain
the :admin role).
Do you have any idea how that is possible?

betasheet

unread,
Nov 23, 2011, 12:06:58 PM11/23/11
to cantango
The problem persists. We've tried using permits instead of
permissions, those show up in the log as "registered", but are never
selected nor build by the PermitFinder / PermitBuilder.
The user's role_list does contain the respective role though.

Kristian Mandrup

unread,
Nov 23, 2011, 12:24:40 PM11/23/11
to cant...@googlegroups.com
I recommend that you try running the specs relevant to RolePermits, then debug from there.

I also think it would be better if you could refactor the master branch to exclude all the files from "cantango-config" and then instead create a gem dependency to "cantango-config". I think the error might well be caused by some configuration bug. I made a few fixed in the cantango-config gem.

Tonight I am working on each engine separately, I've just created a "permissions" project where I have moved anything relevant only to this engine.
Should make it much easier to track down bugs and maintaing the project in general. I'm sorry you are having all this trouble, but then again,
real life usage is what really can propel this project forward! Thanks!

Kristian

betasheet

unread,
Nov 24, 2011, 4:27:57 AM11/24/11
to cantango
Thanks Kristian,

we've managed to find the cause of the problem:
The troles plugin only generated a 'role_list' method in the user
class. But CanTango expects a 'roles_list' method (with an 's').
I guess this could be a problem in your demo app as well.

Best regards
Eric

Kristian Mandrup

unread,
Nov 24, 2011, 6:00:46 AM11/24/11
to cant...@googlegroups.com
Perfect! Thanks! I keep tripping up on the naming of that method!!! Could you make a pull request ;)
I will work with Stanislaw tonight in order to refactor all the new cantango projects towards a 1.0 release with a much better design , much easier to manage, debug etc.

Good luck!

Kristian Mandrup

unread,
Nov 24, 2011, 6:47:37 AM11/24/11
to cant...@googlegroups.com
You can also configure your way out of this bug.

CanTango.config.roles.list_method = :role_list

I think the optimal solution would be to change the troles api, to use :roles_list. What do you think?

Den 24/11/2011 kl. 10.27 skrev betasheet:

Reply all
Reply to author
Forward
0 new messages