Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Hash of conditions causes 'wrong number of arguments' for other resource checks #693

Open
squirreltypo opened this Issue Jul 22, 2012 · 2 comments

Comments

Projects
None yet
3 participants

Firstly, thank you for this awesome gem! Its implementation is so easy compared to others I have tried!

I have a User resource that I have applied a hash condition on. I also have a :report resource (controller only, no model) and when I run a can? in a view against this resource, I get wrong number of arguments (0 for 1).

class UsersController < ApplicationController
    load_and_authorize_resource
end

class ReportsController < ApplicationController
  load_and_authorize_resource :class => false
end

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)

    # Owner can only update their account
    can :update, User, :user_id => user.id

    if user.role? :reporting
      can :manage, :report
    end
end

# This line in view (show.rb) causes the arguments error
    - if can? :read, :report
Collaborator

andhapp commented Jul 22, 2012

@squirreltypo: I could not replicate the issue. This is how I tried:

1. Fire up rails console: rails c
2. Create a user: user = User.create(username: 'user1', password: 'user1') # My user is very minimal
3. Create ability instance: ability = Ability.new(user)
4. Run: ability.can?(:read, :report) # and it doesn't throw any errors. For me, it may be returning an incorrect result, as I created dummy role? method for user, but no errors

Please try and follow these steps and see if you can replicate the error. Thanks.

xhoy commented Jul 1, 2014

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