Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Is CanCan needlessly creating many Ruby objects when DB rules are involved? #460

fj opened this Issue · 3 comments

4 participants

fj commented

When I write a rule that involves a scope, like

class Ability
  def initialize(user)
    can :frobble, Bucket, Bucket.frobbleable_by(user)

it seems CanCan stores the results of calling the frobbleable_by scope, and turns each and every result into a Ruby object. That seems undesirable and creates a lot of GC stress. Would it be better if it did this instead?

  • Keep the query around, but don't execute it.
  • If you need to decide if a given Bucket is frobbleable_by, ask the backing store if that bucket is in this scope.

This would delay creating any unneeded objects until the moment when the Rule is actually needed. Thoughts?


Can you try the most recent version to see if your issue has been resolved? This issue is tagged 2.0, so you'll want to use the master branch.

This is one of the oldest CanCan issues with no discussion. CanCan is struggling right now to implement support for rails 4, and the issue count is nearing 200. It would be a big help if we could close a few old issues and get the issue count down. Thanks!


We are facing the same problem and after tracking it down we came up with this solution:


Unfortunately it's not good enough to make a pull request since we don't get the test suite running locally. Besides that it takes a more generic solution. But in our case it's working for now and maybe this is a good starting point to get around this issue.


Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013.
Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.