cancan icon indicating copy to clipboard operation
cancan copied to clipboard

Have to use block and standard

Open michaelmoulsdale opened this issue 11 years ago • 4 comments

I have a large number of controllers and so started to use the following format in ability.rb

can :manage, [User, Currency, Vacation, Account, etc.]

However, I got some inconsistent behaviours and found that I had to use both the block and single method.

i,e,

can :manage, [User, Currency, Vacation, Account, etc.] can :manage, :users can :manage, :currencies can :manage, vacations etc.

So not pretty. Has this been seen elsewhere?

michaelmoulsdale avatar Jul 21 '13 13:07 michaelmoulsdale

It is probably a mistake to define the same ability twice, eg. for the constant User and the symbol :user. Don't repeat yourself.

Also, you describe this

can :manage, [User, Currency, Vacation, Account, etc.]

as a "block", but the correct term is "array". Please see Containers, Blocks, and Iterators.

For cancan usage, please read Defining Abilities, if you haven't yet.

Please remember that github issues are for bugs or suggested features. Questions about usage are more appropriate on stackoverflow.com/tags/cancan.

jaredbeck avatar Jul 22 '13 04:07 jaredbeck

I agree defining twice is a bad idea, and that is my point. I have to define twice to make it work ... I mainly only want to use arrays due to the large number of abilities being defined. However, I need a couple of singles due to some outliers. What I have found is that if I do not define each ability both in an array and in a single item, some functionality does not behave as expected. This I believe is a bug, which is why I have raised it here.

I'm going to update my code to only have arrays, but with some only including a single item to see if that is the cause

michaelmoulsdale avatar Jul 22 '13 05:07 michaelmoulsdale

This I believe is a bug ..

OK, this is the right place for bugs. :) The next step is to write a failing test. Cancan uses rspec 2.6 for testing.

jaredbeck avatar Jul 22 '13 05:07 jaredbeck

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!

xhoy avatar Jul 01 '14 07:07 xhoy