load_resource and load_and_authorize_resource both are not working #732

Open
HangingClowns opened this Issue Aug 30, 2012 · 6 comments

Comments

Projects
None yet
4 participants

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 b4285ae

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

      def new
        @company = Company.new
      end

    end
Collaborator

mikepack commented Sep 26, 2012

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

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

davefp commented Mar 12, 2013

Hey, is this still an issue?

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

davefp commented Mar 13, 2013

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 Apr 10, 2014

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment