cgf
cgf

Reputation: 3509

current_user method not found (Rails, Devise, Cancan)

I am using Rails 3.2, Devise and Cancan for an application with 3 user categories: Companies, Customers and Admins.

My problem is that I get this:

undefined local variable or method `current_user' for #<HomeController:0xb4fd217c>

In HomeController I have:

class HomeController < ApplicationController
  before_filter :authenticate_customer!
  load_and_authorize_resource :class => false

  def index
        render 'index'
    end

end

Also, in the view:

- content_for :title, 'Home'
= link_to('Logout', destroy_customer_session_path, :method => :delete)

I am not calling current_user anywhere in my code.

Any ideas?

Upvotes: 0

Views: 1838

Answers (1)

cthulhu
cthulhu

Reputation: 3726

CanCan makes two assumptions about your application.

  • You have an Ability class which defines the permissions.
  • You have a current_user method in the controller which returns the current user model.

You can override both of these by defining the current_ability method in your ApplicationController.

https://github.com/ryanb/cancan/wiki/Changing-Defaults

Upvotes: 3

Related Questions