Rules Problems

22 views
Skip to first unread message

Matt

unread,
Jun 18, 2012, 1:43:23 PM6/18/12
to cant...@googlegroups.com
I'm having an issue where an ability has a 2D array of rules after initialization:

@rules=[[#<CanCan::Rule:0x007fc222435f30 @match_all=false, @base_behavior=true, @actions=[:read], @subjects=[#<Consumer...>], @conditions={"users_roles.user_id"=>4}, @block=nil>]]

I worked around it by adding a method to flatten the rules, but I have no idea where the nesting is happening.

Also, I couldn't get the CanCan method #accesible_by to work with this rule, so I looked at how CanCan was creating the SQL query. There's a method in /model_adapters/active_record_adapter called #database_records that should get the conditions I've set, but the @rules variable it calls is empty. I don't know how it's being set correctly in CanTango and yet stays empty for CanCan. I'd appreciate any thoughts people have.

Kristian Mandrup

unread,
Jun 18, 2012, 3:30:58 PM6/18/12
to cant...@googlegroups.com
Hi Matt,

Which version of CanTango are you using? I recommend anyone to use cantango-permits as the basis instead of the old cantango project 0.9.x. I'm aware there is a problem with the @rules not being flattened in the later versions of the gem and I have fixed this problem and refactored and spec'ed everything in canton-permits and the other supporting cantango gems (now split into several gems with more granular responsibility/functionality).
I still need to finish the cantango-permit_store and cantango-cache however, but the rest have been tested and work much better than in the original project.

Matt

unread,
Jun 18, 2012, 5:24:30 PM6/18/12
to cant...@googlegroups.com
Thanks for the response Kristian. I would like to switch to cantango-permits, but I'm having issues getting that to run. I posted those issues in another post. But I'll keep trying to get that working if it will handle the rules correctly.

Kristian Mandrup

unread,
Jun 18, 2012, 5:34:09 PM6/18/12
to cant...@googlegroups.com
Oh? What if you run the cantango-permits specs? unfortunately I have yet to use cantango-permits in a Rails project myself. But I want to do that soon. Would be nice to port the old cantango dummy apps (also in the specs folder) to cantango-permits. Please let me know about your problem with cantango-permits. Good luck!

Matt

unread,
Jun 18, 2012, 6:41:59 PM6/18/12
to cant...@googlegroups.com
I just tried running the specs. I had to make a few changes to get past some errors, but now I'm stuck with this:

cantango-permits/spec/cantango/config/engines/permit_spec.rb:5:in `<top (required)>': uninitialized constant CanTango::Config::Engines::Permit (NameError)

The closest thing I could find was in permits_ext/config/engines/permit.rb, but the class is:

module CanTango
  class Config
    class Engines
      class PermitEngineConfig < EngineConfig

I tried changing that to just Permit (and updating the loading), but that didn't work either, so I'm stuck.

Kristian Mandrup

unread,
Jun 19, 2012, 2:48:09 AM6/19/12
to cant...@googlegroups.com
Wow! That looks completely wrong. Looks like a mix of the new and old module namespacing. To get it working we need to look into cantango-core and cantango-config I think.

The correct end result should look something like this:

module CanTango
  class Config
    class Engines
      class Permit < Base

Matt

unread,
Jun 19, 2012, 12:53:02 PM6/19/12
to cant...@googlegroups.com
Ok, I was able to get the permits specs to run, but there are a bunch of failures. I can't make much headway on fixing them either because I'm not sure how it's supposed to work (i.e. if the specs are right or the code is right). My branch is here: github.com/mwean/cantango-permits. I'll try to work on it if I have more time, but it seems to be pretty far away from working.

Kristian Mandrup

unread,
Jun 19, 2012, 5:32:57 PM6/19/12
to cant...@googlegroups.com
Nice!  Thanks Matt.

I'll try to look at it as soon as I have time and work from your branch. Now I'm tired… 11:30 pm. Ttyl.
Reply all
Reply to author
Forward
0 new messages