ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.26k stars 784 forks source link

load_resource and load_and_authorize_resource both are not working #732

Open allenwyma opened 12 years ago

allenwyma commented 12 years ago

I'm trying to load the resources using either load_resource or load_and_authorize_resource, but it doesn't seem to load the resource at all. I keep getting errors in my rspec controller test that @companies is nil or in my cucumber test that i can't cycle through @companies cause it's nil.

I'm using cancan straight from github repo at rev b4285ae43c7c048a26e2c5918bdfc2570d848b67

   class CompaniesController < ApplicationController
      load_resource
      # load_and_authorize_resource
      def index
        # @companies = current_user.companies
      end

      def new
        @company = Company.new
      end

    end
mikepack commented 12 years ago

I'm not sure if this will ultimately solve your problem (depending on the rest of your code), but the way you're currently using load_resource will not fetch companies from current_user. In order to fetch companies as a nested resource, you'll need to add a :through => :current_user attribute on load_resource, like so:

load_resource :through => :current_user
allenwyma commented 12 years ago

Still not working. It doesn't seem to load the resource at all, still.

davefp commented 11 years ago

Hey, is this still an issue?

allenwyma commented 11 years ago

As far as I know. I haven't tried again, still waiting for someone to take a look at this issue.

davefp commented 11 years ago

I recommend trying again with the most recent version of the gem to make sure it hasn't been fixed elsewhere.

If that doesn't help, please post your ability.rb file as well as the current_user method that CanCan relies on. The model file (which I assume is company.rb) would also be useful.

xhoy commented 10 years ago

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still. Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!