Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

undefined method `cannot?' #34

Closed
dankest opened this issue Jan 21, 2010 · 3 comments
Closed

undefined method `cannot?' #34

dankest opened this issue Jan 21, 2010 · 3 comments

Comments

@dankest
Copy link

dankest commented Jan 21, 2010

I'm trying to authorize a controller that does not have a model. When I try to load the controller "/calendar/patient_calendar", I get the error:
undefined method `cannot?' for CalendarController:Class

Here's my controller:

class CalendarController < ApplicationController
  layout "users"
  before_filter(:only => :patient_calendar) { unauthorized! if cannot? :read, :patient_calendar }

  def patient_calendar
  end

  def public_calendar
  end

end

And here are my abilities:

class Ability
  include CanCan::Ability

  def initialize(user)

    if user.nil?
      can :create, [Message, Gwapp]
      can :read, :public_calendar
    elsif user.user_type == "admin"
      can :manage, :all
    end

  end
end

Any idea what's going on?

@StevenR
Copy link

StevenR commented Jan 30, 2010

I appear to be having the same issue. I notice that if I move the unauthorized! call into the individual methods, there is no further error around undefined method `cannot?' for ...

@StevenR
Copy link

StevenR commented Jan 30, 2010

Try,
before_filter(:only => :patient_calendar) { |controller| controller.unauthorized! if controller.cannot? :read, :patient_calendar }

This worked for me.

@ryanb
Copy link
Owner

ryanb commented Feb 2, 2010

Right, the before_filter passes in the controller object which is what you must call the can?/cannot? methods on.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants