Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

load_and_authorize_resource not working with 1.6.10 #896

Closed
acurley opened this Issue · 2 comments

2 participants

@acurley

I'm working on an application that uses:

  • Rails 4.0.0
  • Cancan 1.6.10
  • Mongoid 4.0.0

I'm not sure which one is causing the problem so this issue might be misplaced.

I've included load_and_authorize_resource in a controller but the index action is not filtering results based on current ability. This does not work:

class InstitutionsController < ApplicationController
  load_and_authorize_resource

  def index
    @institutions = Institution.all
  end
end

However, by manually utilizing the accessible_by method on the class, the records are filtered correctly.

class InstitutionsController < ApplicationController
  def index
    @institutions = Institution.accessible_by(current_ability)
  end
end

Am I missing something? Has anyone else had trouble loading the before_filter capabilities of load_and_authorize_resource?

@ronin

load_and_authorize_resource method sets @institutions variable so you don't to do it in index action

this line

@institutions = Institution.all

replaces what was set in before_filter

@acurley

Thanks. Somehow I missed that. Closing...

@acurley acurley closed this
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.